Esempio n. 1
0
        private string GenerateType(SetSelection selection, string operationName = null)
        {
            if (selection.SpecifiedTypeName is object)
            {
                if (specifiedNameToUniqueIdentifierLookup.TryGetValue(selection.SpecifiedTypeName.Value, out var key) && key != selection.UniqueIdentifier)
                {
                    this.AddError($"'{selection.SpecifiedTypeName.Value}' already defined with different fields", selection.SpecifiedTypeName.Location);
                }
            }

            var lookupName = $"{operationName}_{selection.SpecifiedTypeName?.Value ?? selection.UniqueIdentifier}";

            if (this.typeLookup.ContainsKey(lookupName))
            {
                return(this.typeLookup[lookupName]?.Name);
            }

            string name = selection.SpecifiedTypeName?.Value ?? FindBestName((operationName ?? selection.RootType.Name), "Result");

            TypeViewModel type = BuildTypeViewModel(selection, name, lookupName);

            if (selection.SpecifiedTypeName is object)
            {
                specifiedNameToUniqueIdentifierLookup[selection.SpecifiedTypeName.Value] = selection.UniqueIdentifier;
            }

            return(type.Name);
        }
Esempio n. 2
0
        public Operation(GraphQLOperationDefinition op)
        {
            this.operation = op;

            Name = op.Name?.Value;

            Selection = new SetSelection(operation.SelectionSet);
        }
Esempio n. 3
0
        private TypeViewModel BuildTypeViewModel(SetSelection selection, string name, string lookupName)
        {
            TypeViewModel type = new TypeViewModel(name);

            this.typeLookup.Add(lookupName, type);
            this.typeCollection.Add(type);
            type.Fields = selection.Fields.Select(x => new NamedTypeViewModel()
            {
                Name = x.Name,
                Type = GenerateTypeReference(x)
            }).ToList();

            type.Interfaces = selection.Fragments.Select(x => GenerateType(x)).ToList();
            return(type);
        }
Esempio n. 4
0
        private string GenerateType(SetSelection selection, string operationName = null)
        {
            if (typeLookup.ContainsKey($"{operationName}_{selection.UniqueIdentifier}"))
            {
                return(typeLookup[$"{operationName}_{selection.UniqueIdentifier}"]?.Name);
            }

            var name = FindBestName(operationName ?? selection.RootType.Name, "Result");

            var type = new TypeViewModel(name)
            {
                Fields = selection.Fields.Select(x => new NamedTypeViewModel()
                {
                    Name = x.Name,
                    Type = GenerateTypeReference(x)
                }).ToList()
            };

            typeLookup.Add($"{operationName}_{selection.UniqueIdentifier}", type);
            typeCollection.Add(type);

            return(type.Name);
        }
Esempio n. 5
0
 void HandleSetSelection(SetSelection packet)
 {
     GetPlayer().SetSelection(packet.Selection);
 }