gazuntype / graphQL-client-unity

This repository houses a unitypackage that can be included in your Unity Project to enable it communicate with a graphQL server.
Apache License 2.0
292 stars 50 forks source link

NullReferenceException #6

Closed iamkim17 closed 4 years ago

iamkim17 commented 4 years ago

I'm getting this NullReferenceException every time after I play the unity editor and then click Create Field, also it makes the Create Field button in the inspector not visible. I'm using Unity 2019.3.3f1 version.

NullReferenceException: Object reference not set to an instance of an object GraphQlClient.Core.GraphApi.AddField (GraphQlClient.Core.GraphApi+Query query, System.String typeName, GraphQlClient.Core.GraphApi+Field parent) (at Assets/graphQl-client/Scripts/Core/GraphApi.cs:240) GraphQlClient.Editor.GraphApiEditor.DisplayFields (GraphQlClient.Core.GraphApi graph, System.Collections.Generic.List`1[T] queryList, System.String type) (at Assets/graphQl-client/Scripts/Editor/GraphApiEditor.cs:112) GraphQlClient.Editor.GraphApiEditor.OnInspectorGUI () (at Assets/graphQl-client/Scripts/Editor/GraphApiEditor.cs:59) UnityEditor.UIElements.InspectorElement+<>c__DisplayClass55_0.b__0 () (at <9a184ab867bb42c296d20ace04f48df3>:0) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

seanbiganski commented 4 years ago

This was happening to me and I had to delete the api reference and rebuild my queries. Not convenient but I’m wondering if something changed server side because I hadn’t upgraded Unity or anything recently.

sporeservant commented 4 years ago

I also immediately get this error when attempting to use this library. I am on Mac OSX Mojave 10.14.6 using Unity 2020.01.0b4.3439 Personal.

NullReferenceException: Object reference not set to an instance of an object
GraphQlClient.Core.GraphApi.GetSchema () (at Assets/graphQl-client/Scripts/Core/GraphApi.cs:153)
GraphQlClient.Editor.GraphApiEditor.OnInspectorGUI () (at Assets/graphQl-client/Scripts/Editor/GraphApiEditor.cs:20)
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass58_0.<CreateIMGUIInspectorFromEditor>b__0 () (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorElement.cs:532)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/builduser/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:189)

Steps to reproduce:

sporeservant commented 4 years ago

I can confirm that in my case it was a user error. I was using a GraphQL endpoint that was invalid.

For example, it should have been https://mywebsite.com/, but instead I put in https://mywebsite.com/graphql.

The error that was given though I will say has a strange look about it that seems to suggest something else went wrong, like maybe an incompatible dependency or something.

After correcting the URL I was using, this went away swiftly.

Cheers 🍻

gazuntype commented 4 years ago

hi @sporeservant sorry i'm just getting back to you. glad to see your issue was fixed! closing it now.

kaifaust commented 4 years ago

This was happening to me and I had to delete the api reference and rebuild my queries. Not convenient but I’m wondering if something changed server side because I hadn’t upgraded Unity or anything recently.

+1. This happens to me every time I reopen the Unity project or use Unity Collab. The inspector fails to load the api reference UI.

Screen Shot 2020-06-03 at 6 41 04 PM

Stack: Unity v2019.3.1f1

The error I get:

NullReferenceException: Object reference not set to an instance of an object
GraphQlClient.Core.GraphApi.GetSchema () (at Assets/graphQl-client/Scripts/Core/GraphApi.cs:153)
GraphQlClient.Editor.GraphApiEditor.OnInspectorGUI () (at Assets/graphQl-client/Scripts/Editor/GraphApiEditor.cs:20)
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass55_0.<CreateIMGUIInspectorFromEditor>b__0 () (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorElement.cs:521)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at /Users/builduser/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:187)
gazuntype commented 4 years ago

hi,

no, nothing changed server side as the client doesn't connect to anything besides your own servers.

i'm not sure what could have caused this problem. were there any errors at all in your console? because for the introspect button to not even be there, there has to be some sort of errors.

if you can't remember, can you try to recreate the situation that led to this issue? if you successfully can, can you tell me the steps to recreate the issue so i can properly debug it from my end.

sorry for the inconvenience this caused.

best, Tade.

On Thu, 4 Jun 2020 at 02:43, Kai Faust notifications@github.com wrote:

This was happening to me and I had to delete the api reference and rebuild my queries. Not convenient but I’m wondering if something changed server side because I hadn’t upgraded Unity or anything recently.

+1. This happens to me every time I reopen the Unity project or use Unity Collab. The inspector fails to load the api reference UI.

[image: Screen Shot 2020-06-03 at 6 41 04 PM] https://user-images.githubusercontent.com/3498300/83705442-cfb55b00-a5c9-11ea-8e2a-cf1a330b490a.png

Stack: Unity v2019.3.1f1

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/Gazuntype/graphQL-client-unity/issues/6#issuecomment-638550886, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFP64BGGCOPACYXNY6BMXXLRU332RANCNFSM4MYMZBHA .

FromSi commented 4 years ago

I found a solution for myself. I turned off CSRF :D

gazuntype commented 4 years ago

ah great.

On Sun, Jul 26, 2020, 2:02 PM FromSi notifications@github.com wrote:

I found a solution for myself. I turned off CSRF :D

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/Gazuntype/graphQL-client-unity/issues/6#issuecomment-663985249, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFP64BGADGJPCVI7ACUD57TR5QSNRANCNFSM4MYMZBHA .

Chefty commented 3 years ago

@Gazuntype I still had this issue in Unity 2019.4.16f1. I made a pull request (#27) with a quick fix for it. Cheers.

Chefty commented 2 years ago

@gazuntype we should re-open this issue this as the error actually persist. When selecting Create Field, it stills throw the following error:

NullReferenceException: Object reference not set to an instance of an object GraphQlClient.Core.GraphApi.AddField (GraphQlClient.Core.GraphApi+Query query, System.String typeName, GraphQlClient.Core.GraphApi+Field parent) (at Assets/3rd-Party/graphQl-client/Scripts/Core/GraphApi.cs:286) GraphQlClient.Editor.GraphApiEditor.DisplayFields (GraphQlClient.Core.GraphApi graph, System.Collections.Generic.List`1[T] queryList, System.String type) (at Assets/3rd-Party/graphQl-client/Scripts/Editor/GraphApiEditor.cs:111) GraphQlClient.Editor.GraphApiEditor.OnInspectorGUI () (at Assets/3rd-Party/graphQl-client/Scripts/Editor/GraphApiEditor.cs:58) UnityEditor.UIElements.InspectorElement+<>c__DisplayClass59_0.b__0 () (at /Users/bokken/buildslave/unity/build/ModuleOverrides/com.unity.ui/Editor/Inspector/InspectorElement.cs:636) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:189)

Line position might not be accurate (I modified the script) but what I am sure of is that the subFields variable remains null when calling public void AddField(Query query, string typeName, Field parent = null)

So far I was every time deleting the query to create a new one, but with really long queries this became a nightmare to do.

MuhammadFaizanKhan commented 1 year ago

I am using unity 2021.3.19, when i try to edit the query on the inspector. Then, i am getting this null referece error:

NullReferenceException: Object reference not set to an instance of an object
GraphQlClient.Core.GraphApi.CheckSubFields (System.String typeName) (at Assets/graphQl-client/Scripts/Core/GraphApi.cs:225)
GraphQlClient.Editor.GraphApiEditor.DisplayFields (GraphQlClient.Core.GraphApi graph, System.Collections.Generic.List`1[T] queryList, System.String type) (at Assets/graphQl-client/Scripts/Editor/GraphApiEditor.cs:109)
GraphQlClient.Editor.GraphApiEditor.OnInspectorGUI () (at Assets/graphQl-client/Scripts/Editor/GraphApiEditor.cs:59)
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass59_0.<CreateIMGUIInspectorFromEditor>b__0 () (at <428cf2118a4b4a5595a2768b8e39ad35>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
MuhammadFaizanKhan commented 1 year ago

I am using unity 2021.3.19, when i try to edit the query on the inspector. Then, i am getting this null referece error:

NullReferenceException: Object reference not set to an instance of an object
GraphQlClient.Core.GraphApi.CheckSubFields (System.String typeName) (at Assets/graphQl-client/Scripts/Core/GraphApi.cs:225)
GraphQlClient.Editor.GraphApiEditor.DisplayFields (GraphQlClient.Core.GraphApi graph, System.Collections.Generic.List`1[T] queryList, System.String type) (at Assets/graphQl-client/Scripts/Editor/GraphApiEditor.cs:109)
GraphQlClient.Editor.GraphApiEditor.OnInspectorGUI () (at Assets/graphQl-client/Scripts/Editor/GraphApiEditor.cs:59)
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass59_0.<CreateIMGUIInspectorFromEditor>b__0 () (at <428cf2118a4b4a5595a2768b8e39ad35>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

Just debugging it the data is null SchemaClass.data in CheckSubFields method:

   public bool CheckSubFields(string typeName){
            if(schemaClass != null)
            {
                if (schemaClass.data!=null)
                {
                    Debug.Log(schemaClass.data.__schema.types.Count);
                }
                else
                {
                    Debug.Log("schemaClass.data is null");
                }

            }
            Introspection.SchemaClass.Data.Schema.Type type = schemaClass.data.__schema.types.Find((aType => aType.name == typeName));
            if (type?.fields == null || type.fields.Count == 0){
                return false;
            }

            return true;
        }