gazuntype/graphQL-client-unity

NullReferenceException

iamkim17 opened this issue · 12 comments

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)

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.

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:

  • Import unity package
  • Click on "Assets" folder, click Create Api Reference
  • Change name to something like MyGraphQL_API
  • Paste graphql URL
  • press introspect button

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 🍻

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

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)

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

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

@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.

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&)

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;
        }