'GraphQL queries showing error in the .graphQl file
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.
Solution 1:[1]
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.
Solution 2:[2]
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
Solution 3:[3]
I had this same issue... Zizoh and Mahmoud Magdy explained it but ill leave it here with more details to help anyone who needs.. In android studio, in root folder create a .graphqlconfig like this :
change that URL for your server url
]2
after that, click on the play icon in the config file you just created..
]3
And now everything should be working as you would like :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mahmoud Magdy |
| Solution 2 | |
| Solution 3 | Dr.jacky |

