One of the most commonly discussed terms today is the API. A lot of people don’t know exactly what an API is. Basically, API stands for Applicati...
For further actions, you may consider blocking this person and/or reporting abuse
In the example to return a single user:
I get the error:
I really think that this error came from de db.js, did you uploaded it right? Can you upload this code in someplace? I may be able to help you if you do so.
That's the type checking (===) failing there. I had the same issue. Replace the find functions to double equal checks instead of triple, then it should work: users.find(user => user.id == id)
Not sure why the typecheck doesn't work. Perhaps the ID! in schema.graphql is returning a string by default?
Yup, that was it.
spent like 30 mins trying to get it to work, triple = kills the functionality
This helped me better understand '==' vs '==='
github.com/getify/You-Dont-Know-JS...
EDIT: 'ID' type is serialised to String in graphql. So really, the comparison works as expected. If anything, this needs better error handling.
apollographql.com/docs/apollo-serv...
This is very good article to explain what is GraphQL and why it's being used. I have been using graphQL for many time and this tool helped to read it better sometime from API, GraphQL Formatter jsonformatter.org/graphql-formatter.
Keep up the good work @leonardomso
I like this formatting tool too.. and yes @leonardomso this is amazing article.
Added this to my reading list :D
Do you have any resources concerning directives? I saw they're extensively used in AWS AppSync and seem really powerful.
I didn't work with AWS AppSync yet, so I won't be able to help you with that 😞
No problem.
I just had the impression directives are a general GraphQL concept :)
Thanks for the very comprehensible intro to graphQL!
If I may add, the part about deleting users is a little confusing:
deleteUser: we should pass an ID, name, email, and age. It should return a new user to us.
It shouldn't return a new user, am I right? And is there a particular reason you want to return the user after deleting it?
Oh, my bad. It should return the deleted user to us, just to make sure that the mutation worked fine.
A good read, thanks!
@Schema part: Now it's easier to fully understand a schema with visualization provided by GraphQL Editor (graphqleditor.com/). Just upload it from URL and enjoy beautifully drawn schema :)
The error handling in delete is interesting. REST would dictate that the deletion of a non existant user works (idempotency) and hence that the deleted user cannot be returned. Does GraphQL not have this concept?
I don't know if I understood correctly what you mean, but the way I think is, instead you return the deleted user you could return anything like a string saying "User deleted!" or something.
I was asking if GraphQL had the REST concept of idempotency (i.e. if you repeat a data-altering operation, then it behaves the same way - hence the 'deleting a deleted user'). Your implementation isn't idempotent, and I was asking if it should have been. Obviously if you delete something that's not there, the only sensible reply is probably 204 - again REST (IIRC) says this is what you should do, GraphQL...?
Nicely explained Leonardo! Thank you !!
Hello, Thanks for your post!!
I am using the graphql in vue js
so api is frontend-test-api.aircall.io/graphql
and query is as follows
query call($id:ID!) {
Call {
id
direction,
from,
to,
duration,
via,
is_archived,
call_type,
created_at,
notes{
id,
content
}
}
}
but I am getting the 404 errors
can you help me?
Muito foda cara, parabéns pelo artigo e muito obrigado por uma explicação tão concisa, simples e bem descrita!
Obrigado!!!
Hey Leonardo! I was just looking for a comprehensive and good tutorial on the topic. Great writeup, really helped me!
Not sure why but for me the strict eq comp operator didn't work but the abstract one did, like they are of different type?!
Anyway with == (user => user.id == id) it did work (in latest chrome...)
Typo here. Only the ID is necessary.
Hola Leonardo.
Can it become a series? 🤔
Yes, why not? I've been thinking to write a series about GraphQL, explaining more deep about Queries, Mutations, and Subscriptions. What do you think?
I'll be looking forward for it.
Please do it!
Clear and simple explained.
Nice post mate! 😊
Good Job, Nice explication, What about Graphql integration with microservices architecture
Added to my reading list, too!
Thank you @leonardomso
Does GraphQL rely on a mongoDB server? Or does it directly run within a node instance? If the later -how does this work? The database is stored on the node-server?
what about relational data (class has students ). example:hasMany, belongTo
Wow, this was an amazing article. Been searching this from ages !
Leonardo excelent post, thank you very much