Beispiel #1
0
 public InputFieldDescriptor(
     string name,
     IType type,
     IInputField field,
     IInputClassDescriptor inputObjectType)
 {
     Name            = name ?? throw new ArgumentNullException(nameof(name));
     Type            = type ?? throw new ArgumentNullException(nameof(type));
     Field           = field ?? throw new ArgumentNullException(nameof(field));
     InputObjectType = inputObjectType;
 }
 public ArgumentDescriptor(
     string name,
     IType type,
     VariableDefinitionNode variableDefinition,
     IInputClassDescriptor inputObjectType)
 {
     Name = name
            ?? throw new ArgumentNullException(nameof(name));
     Type = type
            ?? throw new ArgumentNullException(nameof(type));
     VariableDefinition = variableDefinition
                          ?? throw new ArgumentNullException(nameof(variableDefinition));
     InputObjectType = inputObjectType;
 }
        private ICodeDescriptor GenerateOperation(
            ObjectType operationType,
            OperationDefinitionNode operation,
            ICodeDescriptor resultType)
        {
            var arguments = new List <Descriptors.IArgumentDescriptor>();

            foreach (VariableDefinitionNode variableDefinition in
                     operation.VariableDefinitions)
            {
                string typeName = variableDefinition.Type.NamedType().Name.Value;

                if (!_schema.TryGetType(typeName, out INamedType namedType))
                {
                    throw new InvalidOperationException(
                              $"The variable type `{typeName}` is not supported by the schema.");
                }

                IType type = variableDefinition.Type.ToType(namedType);
                IInputClassDescriptor inputClassDescriptor = null;

                if (namedType is InputObjectType inputObjectType)
                {
                    inputClassDescriptor =
                        GenerateInputObjectType(inputObjectType);
                }

                arguments.Add(new ArgumentDescriptor(
                                  variableDefinition.Variable.Name.Value,
                                  type,
                                  variableDefinition,
                                  inputClassDescriptor));
            }

            string operationName =
                CreateName(GetClassName(operation.Name.Value) + "Operation");

            return(new OperationDescriptor(
                       operationName,
                       _namespace,
                       operationType,
                       operation,
                       arguments,
                       _query,
                       resultType));
        }