0
\$\begingroup\$

I am using GraphQL plugin from https://github.com/Gazuntype/graphQL-client-unity. I have a long query from which I am parsing it to JSON to get individual values. It all works fine. Unfortunately the problem appears when using SetArgs() in a nested {}. For example, here is my query:

{
  System(ID: "1") {
    model {
      type {
        SystemModel{
          CreationModel(isModelCreated: true) {
          name
          }
         }
        }
     }
   }
}

And here is my Unity code:

public async void GetSystemID () {
        GraphApi.Query query = Graph.GetQueryByName ("System", GraphApi.Query.Type.Query);
        query.SetArgs (new { ID= "1", isModelCreated = true }); //How do I provide isModelCreated here

        UnityWebRequest request = await NestedQuery.Post (query);
        JSONNode itemsData = JSON.Parse (request.downloadHandler.text);
        var parseJSON = JSON.Parse (request.downloadHandler.text);

    }

So in SetArgs, I have to provide a list of arguments, for example ID: "1" and isModelCreated: true. I am able to provide the first argument, but unfortunately the nested query's argument - isModelCreated is not getting recognized as it treats it as:

System(ID: "1", isModelCreated: true) {}

Do I have to add multiple {} so that it comes in right order or is there a cleaner way to achieve this?

\$\endgroup\$
4
  • \$\begingroup\$ @Philipp I am using GraphQL plugin from github.com/Gazuntype/graphQL-client-unity. \$\endgroup\$
    – Saif
    Mar 3 '21 at 14:07
  • \$\begingroup\$ Also, it looks like there's an example of assigning fields in nested objects in the documentation you linked: createUser.SetArgs(new{objects = new{id = "idGiven", name = "nameGiven"}}); \$\endgroup\$
    – DMGregory
    Mar 3 '21 at 14:17
  • \$\begingroup\$ @DMGregory sorry I shall add that now. I have tried doing it in nested way they have described it but to no luck it is successful. \$\endgroup\$
    – Saif
    Mar 3 '21 at 14:55
  • 3
    \$\begingroup\$ Sounds like you should show us THAT code in your question too. Remember, we cannot see anything you don't show us. \$\endgroup\$
    – DMGregory
    Mar 3 '21 at 15:02
0
\$\begingroup\$

Based on the example in the docs, it looks like you want something like:

query.SetArgs (new { ID= "1", 
    model = new {
        type = new {
            SystemModel = new {
                CreationModel = new { 
                    isModelCreated = true 
                }
            }
        }
    }
});

If this didn't work for you, you should edit your question to include the exact code you used and the exact error message, unwanted output, or other problem symptoms you observed.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .