GraphQL queries showing error in the .graphQl file
Asked Answered
C

3

9

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.

Conradconrade answered 21/8, 2019 at 9:21 Comment(4)
What specific errors are you seeing?Allier
@DanielRearden Unknown field : The parent selection or operation does not resolve to a valid schema type.Conradconrade
I am experiencing the same, Were you able to fix this?Gigi
@ShyamnathMallinatham not yet. Not enough resources available on the net regarding graphql with AndroidConradconrade
T
5

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

Testamentary answered 21/1, 2021 at 22:32 Comment(1)
what if we need to add multiple schemas ?Morton
D
4

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.

Dayna answered 15/10, 2019 at 15:7 Comment(0)
F
0

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 :

enter image description here

change that URL for your server url

enter image description here]2

after that, click on the play icon in the config file you just created..

enter image description here]3

And now everything should be working as you would like :)

Feign answered 3/11, 2021 at 1:20 Comment(3)
Please add code and errors as text( using code formatting ), not images. Images are problematic for many reasons, including that they don't allow copy-pasting text for testing or searching.Cornellcornelle
The only code needed to be written is in the Zizoh asnwer... The only reason for me to put this asnwer is to show how to implement those asnwers step by steps, since that may be confusing... :)Feign
But will follow those tips for next asnwers / questions, thanks! :)Feign

© 2022 - 2024 — McMap. All rights reserved.