gazuntype/graphQL-client-unity

After re-introspecting w/ existing queries, return type changes to incorrect type

Opened this issue · 4 comments

I have a query like GetUsers which is set to return user, but after I introspect, return type changes to character. Once this happens, when you click "add field", it causes all the values to be from the character schema instead.

I was able to "solve" this by deleting the query and making the exact same thing again - then the return type becomes correct.

Additionally, when you start building up these deep resolvers, you can imagine that re-creating these every time becomes a huge pain.

Is there no way to create the queries as text in files rather than this cumbersome tree UI?

Thanks!

Another interesting behavior was that at one point, I added two resolvers to my User object and then did an Introspect. Afterward, this time, the return type did not change, but only 1 of the two properties were available after Introspection. Then I created a brand new query of the same type and both were available.

There must be something going, maybe, with the .asset file after introspection. I will try to keep an eye on the file and report back anything that comes up.

hi,
i am just seeing this. does the return always change whenever you introspect? or it only happens occasionally/randomly? if so, can you try to recreate the situation it happens so i can pinpoint the source?

also, if you don't want to use the tree ui, you can always create your queries in text as files and simply use HttpHandler.PostAsync to make the call to your server.

Hey Gazuntype,

Honestly I just stopped using the GUI completely, and I use some of the code your GUI uses to create some API around .gql files. But the solution I have right now is kind of hacky.

I am basically just doing this - I defined some functions to make a small API:

public struct CreateQueryOptions
        {
            public string name;
            public GraphApi.Query.Type queryType; 
            public string root;
            public string returnType;
            public string projection;
            public object queryArgs;
        }

        public static GraphApi.Query CreateQuery(
            CreateQueryOptions options
        )
        {
            GraphApi.Query query = new GraphApi.Query{
                    fields = new List<GraphApi.Field>(),
                    isComplete = false,
                    name = options.name,
                    query = options.projection
                        .Replace(System.Environment.NewLine, "\n"),
                    queryOptions = new List<string>(),
                    queryString = options.root,
                    returnType = options.returnType,
                    type = options.queryType
            };

            if (options.queryArgs != null)
            {
                query.SetArgs(options.queryArgs);
            }

            return query;
        }

and then I use them like this:

       public async Task<Models.User> GetUser(
            string userName = null
        )
        {
            CreateQueryOptions options = new CreateQueryOptions {
                name = "GetUsers",
                queryType = GraphApi.Query.Type.Query,
                root = "users",
                returnType = "User",
                projection = 
                    @"
    id
    name
    userName
    emailAddress
    firstName
    lastName
                    ",
                queryArgs = new { 
                    where = new {
                        userName,
                    }
                }
            };

            GraphApi.Query getUser = CreateQuery(options);

            UnityWebRequest request = await rttGraphQLApi.Post(getUser);

            if (request.isNetworkError)
            {
                Debug.Log("Error running GetUserByEmail: " + request.error);
                return null;
            }

            string data = request.downloadHandler.text;

            // GetUserByEmailResults parsed =  JsonConvert.DeserializeObject<GetUserByEmailResults>(data);
            JObject parsed  = JObject.Parse(data);
            IList<JToken> results = parsed["data"]["users"].Children().ToList();
            IList<Models.User> users = new List<Models.User>();
            foreach (JToken result in results)
            {
                Models.User user = result.ToObject<Models.User>();
                users.Add(user);
            }

            if (users.Count > 0)
            {
                Debug.LogFormat("Found {0} total user accounts matching.", users.Count);
                Models.User user = users[0];
                return user;
            }
            else
            {
                Debug.Log("No users found with specified email.");
            }

            return null;
        }

As far as recreating the problem, I just had a mixture of Queries and Mutations against a relatively sophisticated schema.

This still hasnt been fixed in almost a year, @gazuntype do you intend to resolve this issue? It causes the GUI to be unusable