I am doing a demo project on graphql queries. Followed all the required steps and downloaded schema.json from my dummy graphql server on graphcool. However when I am writing the .graphql file which contains the graphql queries, android studio is showing me errors for the fields. Even after I have successfully built the project, still the errors persist. I have a dummy graphql server which has type Employee and 5 fields : name,id,height,age and work.
I have tried making a new project and re writing all the code. I have tried rebuilding and cleaning my project, etc,. I have re downloaded the schema.json file and tried deleting and rewriting the .graphql file. Yet the errors are still thrown.
query getAllEmployeeDetails{
allEmployees{
name
id
height
age
work
}
}
this is my .graphql file. Android studio throws errors on all the 5 fields and also throws error on the "allEmployees" too.
The corresponding query on graphql backend is:
query{
allEmployees{
name
id
height
age
work
}
}
which works fine.
Expected result is that android studio shouldn't be throwing an error on the fields.
In you want to remove the outer GraphQLError to access the originally thrown error you can use unwrapResolverError from @apollo/server/errors . The unwrapResolverError function can remove the GraphQLError wrapping from a resolver error or return the error unaltered if it isn't from a resolver.
Calling the mutate function returned by the hook returns a Promise. If the request is successful, the Promise will resolve to a response object that includes the data returned by the server. If the request fails, the Promise will reject with the error.
GraphQL errors These are errors related to the server-side execution of a GraphQL operation. They include: Syntax errors (e.g., a query was malformed) Validation errors (e.g., a query included a schema field that doesn't exist) Resolver errors (e.g., an error occurred while attempting to populate a query field)
When using GraphiQL or any other client for testing GraphQL queries, you might need to debug the request processing. You can use Xdebug for debugging the PHP execution of a GraphQL query just as you would for other HTTP requests. To start debugging, add the ? XDEBUG_SESSION_START=PHPSTORM parameter to the endpoint URL.
I have faced the same error you have mentioned in the comment, the whole queries show the same error every field couldn't be resolved but in development the code works fine. So I searched many times until I found this issue
After opening the .graphqlconfig file there is a button to run a query called "introspection query" here like this snapshot here
A new file will be added automatically to your graphql folder called "schema.graphql", It is a file contains the whole inputs, types & scalars by the end-point, after generating the file, everything will be normal again and the errors will be vanished.
Add a file named .graphqlconfig
to the root of your project. The file's content should be something like this:
{
"name": "Remote Schema",
"schemaPath": "remote-schema.graphql",
"extensions": {
"endpoints": {
"Apollo Fullstack Tutorial": {
"url": "https://apollo-fullstack-tutorial.herokuapp.com/",
"headers": {
"user-agent": "JS GraphQL"
},
"introspect": true
}
}
}
}
Change the url
to your server's endpoint and change "Remote SWAPI GraphQL Endpoint" to better describe your server.
Also, see here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With