NavidK0 / SimpleGraphQL-For-Unity

A simple graphQL client that allows one to use .graphql files (or code) for queries, mutations, and subscriptions with Unity.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

definition for 'Result' and no accessible extension method 'Result' accepting a first argument of type 'Response<<anonymous type:

zkMyst opened this issue · comments

commented

Hi !
I'm trying to make a simple graphql query, supposed to return an array of integers. I've replaced my query and the value in the example. Nevertheless i'm getting the following error when trying to access response.Result :

Response<<anonymous type: <anonymous type: string tokenId>[] tokens>>' does not contain a definition for 'Result' and no accessible extension method 'Result' accepting a first argument of type 'Response<<anonymous type: <anonymous type: string tokenId>[] tokens>>' could be found (are you missing a using directive or an assembly reference?)

The return from the query is { owner: { tokens: Array<{ tokenID }> } }

Screenshot 2022-12-31 at 13 59 30

The query is supposed to return an array of integers, is it giving me that error because of the return type?

Thanks a lot <3

commented

Actually if I just copy paste the example I do get the same error:

Screenshot 2022-12-31 at 14 32 34

'Response<<anonymous type: <anonymous type: string name> continent>>' does not contain a definition for 'Result' and no accessible extension method 'Result' accepting a first argument of type 'Response<<anonymous type: <anonymous type: string name> continent>>' could be found (are you missing a using directive or an assembly reference?)

(I saw your email, but I'll respond here to keep everything in one place.)

So the documentation is slightly wrong here, since await client.Send() will automatically unwrap the Task object for you. So you don't actually need Result if you do await. If you remove the await, the Result object will appear.

However, I recommend simply doing response.Data.continent.name since you are using async code.

I've gone ahead and updated the documentation as well.

commented

Thanks a lot! I've removed Result from the path and it worked.

If the return from the query is supposed to be

{ owner: { tokens: Array<{ tokenID }> } }

, is the responseType supposed to be

var responseType = new { owner = new { tokens = new { tokenID = "" } } }; ?

It's returning null with my current query setup:

Screenshot 2022-12-31 at 17 31 26

Tokens should be an array in your responseType if that's what you expect.

Something like (Sorry, I didn't test the following code out, but you get the gist):

var responseType = new { owner = new { tokens = new[] { tokenID = "" } } };

If you'd prefer, you can also make a class that contains the exact data structure you want and pass that in as a generic type parameter instead.

[Serializable]
public class GetTokensForOwnerResponse
{
    public Owner owner;

    [Serializable]
    public class Owner
    {
        public Token[] tokens;

        [Serialiable]
        public class Token
        {
            public string tokenID;
        }
    }
}

...
var response = await client.Send<GetTokensForOwnerResponse>(request);
Debug.Log(response.Data);
commented

Edit: found the issue, i didn't add ($id: ID!) to the query in the beggining : ) thanks for your help!

No problem! Closing as solved.