예제 #1
0
        private void SetArguments(GraphContext context, Operation operation)
        {
            foreach (var variable in operation.Variables)
            {
                var name          = variable.Name;
                var graphTypeName = "";
                var namedType     = variable.Type as NamedType;
                if (namedType != null)
                {
                    graphTypeName = namedType.Name;
                }
                else
                {
                    var notNullType = variable.Type as NonNullType;
                    graphTypeName = $"{((NamedType)notNullType.Type).Name}!";
                }

                if (string.IsNullOrWhiteSpace(graphTypeName))
                {
                    throw new GraphException($"Does not specify the GraphType for the argument '{variable.Name}'");
                }

                if (!_graphTypeProvider.TryGetGraphType(graphTypeName, out var graphType))
                {
                    throw new GraphException($"Cannot resolve the GraphQL type '{graphTypeName}'");
                }
                var defaultValue = variable.DefaultValue == null
                    ? null
                    : variable.DefaultValue.Value;
                context.AddArgument(new NamedGraphType(name, graphType, defaultValue));
            }
        }