The GraphQL for Unity Asset can be used to execute GraphQL queries in Unity. The result is set on properties of Unity objects and there is also a Unity Event on the GraphQL Query Object where user-defined function of a GameObject can be triggered every time when a queries returns data or an error.
public class Sample1 : MonoBehaviour
public void ResultEvent(GraphQLResult result)
Debug.Log("Data: " + result.Data.ToString());
Debug.Log("Error: " + result.Errors.ToString());
Create a GameObject with this class as component and then you can drag and drop this GameObject to the Query GameObject and select the “ResultEvent” method. Every time when the query is executed then this function will be called with the result data (or error data).
The GraphQL for Unity Asset uses the Newtonsoft version which is built in newer version of Unity (2020+). If you get an error like this:
Assembly 'Library/ScriptAssemblies/Assembly-CSharp.dll' will not be loaded due to errors: Reference has errors 'GraphQL'.
Assembly 'Assets/GraphQL/Libs/GraphQL.dll' will not be loaded due to errors:
GraphQL references strong named Newtonsoft.Json Assembly references: 184.108.40.206 Found in project: 220.127.116.11.
Assembly Version Validation can be disabled in Player Settings "Assembly Version Validation"
Then you can try to remove NewtonSoft dependency from your project – if you have a dependency. And just use the NewtonSoft version which is already built in and shipped with Unity 2020+. If you use an older version of Unity then you can try to copy the NewtonSoft DLL from 2020 and use this in your older Unity version.
Or you can go to Project Settings -> Player -> Other Settings and deactivate “Assembly Version Validation”
Install the newtonsoft package from Unity. Go into the package manager and click “+” and then select “Add package from git URL” and fill in “com.unity.nuget.newtonsoft-json”.