Daniel Rearden

Mar 11, 2020 16:50
Well, you should get an error, but if you're getting one about the variable being a String, it sounds like a bug with the graphql library. What version are you using?
Mar 11, 2020 16:21
If you change the type back to ID, does it show the same error about the type being a string?
Mar 11, 2020 16:19
In fact, you can verify it's correct because GraphQL Playground would highlight errors in it if it wasn't
Mar 11, 2020 16:18
mutation update($id: ID!, $text: String) {
UpdatePost(id: $id, text: $text) {
id
text
}
}
Mar 11, 2020 16:18
There's no need. If this is what you are running, with the type as ID! instead of ID, then the query is correct
Mar 11, 2020 16:17
No
Mar 11, 2020 16:14
So if that's what you're seeing with the correct query, in GraphQL Playground, I'm at a loss
Mar 11, 2020 16:13
That's effectively the same error, and all I did to produce it was make the $id variable a String instead of an ID
Mar 11, 2020 16:12
Mar 11, 2020 16:12
The odd thing is I know exactly how to reproduce that error, and it has nothing to do with your variable values. It comes down to the definition being incompatible with the argument type
Mar 11, 2020 16:08
What are you entering into the variables tab?
Mar 11, 2020 16:03
You didn't mention in your question, how exactly are you sending the query? Are you using GraphiQL/GraphQL Playground? Is this part of a front end app?
Mar 11, 2020 16:02
So, in other words, if your variable definitions already look like this: $id: ID!, $text: String, and you are still seeing the same error about $id being a String then the issue is not with your query.
Mar 11, 2020 16:02
No worries
Mar 11, 2020 16:02
Hey
Mar 11, 2020 16:00
Like I said, it needs to be $id: ID! instead of $id: ID. But that's not relevant to the error you're seeing. The error implies that whatever query is actually hitting your server has this as a definition: $id: String.
Mar 11, 2020 16:00
If you are still seeing an error after fixing your variable definitions, recheck that it is in fact the same error. The error you pasted doesn't match up to the query you pasted.
Mar 11, 2020 16:00
You don't "convert" a string to an ID. An ID scalar simply accepts strings (and integers) as valid values as outlined in the spec.
 
Jun 23, 2019 03:35
good luck!
Jun 23, 2019 03:34
There's plenty of different schema design concepts different companies have explored, and there's plenty to love and hate about each one
Jun 23, 2019 03:33
GraphQL is still so new, I would hesitate to say there's established best practices
Jun 23, 2019 03:32
If you're trying to wrap your brain around schema design, I found this talk helpful as well: youtube.com/watch?v=2It9NofBWYg
Jun 23, 2019 03:31
Yeah, I can understand that concern and like I said, it's largely a matter of preference
Jun 23, 2019 03:24
@baku You might want to take a look at existing APIs
Jun 23, 2019 03:23
It's also worth mentioning that there's no need for multiple fields like userById, userByEmail, etc. In most cases, it's sufficient to have a single user field with some kind of input object argument with optional fields. Then you can determine which field(s) to filter by programatically inside the resolver.
Jun 23, 2019 03:23
It's a matter of preference. You can do it with mutations too, as long as you understand the drawbacks and necessary workarounds client-side. I personally don't like the approach because 1) it goes against convention 2) its easy enough to group related Query/Mutation fields using naming conventions and 3) auto-completion when using GraphiQL/GraphQL Playground makes it easy enough to write the correct query even if you have a thousand different fields under a root type.
 
Jun 19, 2019 20:56
Good luck!
Jun 19, 2019 20:56
not really familiar enough with TypeORM enough to give more guidance, sorry
Jun 19, 2019 20:55
or modify checkUserName accordingly
Jun 19, 2019 20:55
...or (await membersService.checkUserName(user_name))[0]
Jun 19, 2019 20:55
return members[0]
Jun 19, 2019 20:55
const members = await membersService.checkUserName(user_name)
Jun 19, 2019 20:49
Please refer to Common Scenario #2 here: stackoverflow.com/questions/56319137/…
Jun 19, 2019 20:49
then the user_name field will resolve correctly, and you won't see the error anymore
Jun 19, 2019 20:48
Instead, you want to grab the first item from that array inside your resolver and then return that
Jun 19, 2019 20:48
So you can change your field type to [Member] (a List of Members), but you probably don't want that
Jun 19, 2019 20:47
So that returns an Array, while the type of your field is an Object
Jun 19, 2019 20:43
If you do console.log(await membersService.checkUserName(user_name)) inside your resolver, what is shown?
Jun 19, 2019 20:34
There is no error being thrown by postgres. The errors you're seeing are due to the user_name field resolving to null, which it can't because it's non-null. What does membersService.checkUserName actually return?
Jun 19, 2019 20:30
There is no null error for you to handle. The error you're seeing is because the value being returned is not passing validation
Jun 19, 2019 20:29
@Preston data is null because of how GraphQL handles non-null fields.
Jun 19, 2019 20:14
does membersService.checkUserName return a Member Object, or does it return something else (like a Boolean, or maybe an Object or Array that contains the actual Member)?
Jun 19, 2019 20:13
i.e. checkUserName's resolver should return a Member Object
Jun 19, 2019 20:12
But we often see this sort of error when the resolver doesn't return the response in the correct "shape"
Jun 19, 2019 20:12
Now it's possible that user_name is actually returning null from the database
Jun 19, 2019 20:11
As the error indicates, the field is resolving to null, which it can't because you've made it non-null in the schema
Jun 19, 2019 20:11
checkUserName returns a Member type and that type has a non-null field named user_name
Jun 19, 2019 20:08
The issue you're seeing is not related to input validation.
Jun 19, 2019 20:07
@Preston let's continue this in chat since the comment thread was getting a bit lenghty