public void GetQueryReturnType(Query query, string queryName)
        {
            string endpoint;

            switch (query.type)
            {
            case Query.Type.Query:
                endpoint = queryEndpoint;
                break;

            case Query.Type.Mutation:
                endpoint = mutationEndpoint;
                break;

            case Query.Type.Subscription:
                endpoint = subscriptionEndpoint;
                break;

            default:
                endpoint = queryEndpoint;
                break;
            }
            Introspection.SchemaClass.Data.Schema.Type queryType =
                schemaClass.data.__schema.types.Find((aType => aType.name == endpoint));
            Introspection.SchemaClass.Data.Schema.Type.Field field =
                queryType.fields.Find((aField => aField.name == queryName));

            query.returnType = GetFieldType(field);
        }
        public bool CheckSubFields(string typeName)
        {
            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);
        }
        //ToDo: Do not allow addition of subfield that already exists
        public void AddField(Query query, string typeName, Field parent = null)
        {
            Introspection.SchemaClass.Data.Schema.Type type = schemaClass.data.__schema.types.Find((aType => aType.name == typeName));
            List <Introspection.SchemaClass.Data.Schema.Type.Field> subFields = type.fields;
            int        parentIndex   = query.fields.FindIndex(aField => aField == parent);
            List <int> parentIndexes = new List <int>();

            if (parent != null)
            {
                parentIndexes = new List <int>(parent.parentIndexes)
                {
                    parentIndex
                };
            }
            Field fielder = new Field {
                parentIndexes = parentIndexes
            };

            foreach (Introspection.SchemaClass.Data.Schema.Type.Field field in subFields)
            {
                fielder.possibleFields.Add((Field)field);
            }

            if (fielder.parentIndexes.Count == 0)
            {
                query.fields.Add(fielder);
            }
            else
            {
                int index;
                index = query.fields.FindLastIndex(aField =>
                                                   aField.parentIndexes.Count > fielder.parentIndexes.Count &&
                                                   aField.parentIndexes.Contains(fielder.parentIndexes.Last()));

                if (index == -1)
                {
                    index = query.fields.FindLastIndex(aField =>
                                                       aField.parentIndexes.Count > fielder.parentIndexes.Count &&
                                                       aField.parentIndexes.Last() == fielder.parentIndexes.Last());
                }

                if (index == -1)
                {
                    index = fielder.parentIndexes.Last();
                }

                index++;
                query.fields[parentIndex].hasChanged = false;
                query.fields.Insert(index, fielder);
            }
        }
        public void CreateNewQuery()
        {
            GetSchema();
            if (queries == null)
            {
                queries = new List <Query>();
            }
            Query query = new Query {
                fields = new List <Field>(), queryOptions = new List <string>(), type = Query.Type.Query
            };

            Introspection.SchemaClass.Data.Schema.Type queryType = schemaClass.data.__schema.types.Find((aType => aType.name == queryEndpoint));
            for (int i = 0; i < queryType.fields.Count; i++)
            {
                query.queryOptions.Add(queryType.fields[i].name);
            }

            queries.Add(query);
        }
        public void CreateNewSubscription()
        {
            GetSchema();
            if (subscriptions == null)
            {
                subscriptions = new List <Query>();
            }
            Query subscription = new Query {
                fields = new List <Field>(), queryOptions = new List <string>(), type = Query.Type.Subscription
            };

            Introspection.SchemaClass.Data.Schema.Type subscriptionType = schemaClass.data.__schema.types.Find((aType => aType.name == subscriptionEndpoint));
            if (subscriptionType == null)
            {
                Debug.Log("No subscriptions");
                return;
            }
            for (int i = 0; i < subscriptionType.fields.Count; i++)
            {
                subscription.queryOptions.Add(subscriptionType.fields[i].name);
            }

            subscriptions.Add(subscription);
        }