コード例 #1
0
        private static IEnumerable <Delegation.VariableValue> ResolveUsedRequestVariables(
            ISchema schema,
            NameString schemaName,
            ExtractedField extractedField,
            IReadOnlyDictionary <string, IValueNode> requestVariables,
            ExtractFieldQuerySyntaxRewriter rewriter)
        {
            foreach (VariableDefinitionNode variable in extractedField.Variables)
            {
                string          name      = variable.Variable.Name.Value;
                INamedInputType namedType = schema.GetType <INamedInputType>(
                    variable.Type.NamedType().Name.Value);

                if (!requestVariables.TryGetValue(name, out IValueNode value))
                {
                    value = NullValueNode.Default;
                }

                value = rewriter.RewriteValueNode(
                    schemaName,
                    (IInputType)variable.Type.ToType(namedType),
                    value);

                yield return(new Delegation.VariableValue
                             (
                                 name,
                                 variable.Type,
                                 value,
                                 variable.DefaultValue
                             ));
            }
        }
コード例 #2
0
        private static void ResolveScopedVariableArguments(
            IResolverContext context,
            NameString schemaName,
            SelectionPathComponent component,
            IOutputField field,
            ICollection <Delegation.VariableValue> variables,
            ExtractFieldQuerySyntaxRewriter rewriter)
        {
            foreach (ArgumentNode argument in component.Arguments)
            {
                if (!field.Arguments.TryGetField(argument.Name.Value, out IInputField arg))
                {
                    throw new QueryException(
                              ErrorBuilder.New()
                              .SetMessage(
                                  StitchingResources.DelegationMiddleware_ArgumentNotFound,
                                  argument.Name.Value)
                              .SetExtension("argument", argument.Name.Value)
                              .SetCode(ErrorCodes.ArgumentNotFound)
                              .Build());
                }

                if (argument.Value is ScopedVariableNode sv)
                {
                    Delegation.VariableValue variable =
                        _resolvers.Resolve(context, sv, arg.Type);
                    IValueNode value = rewriter.RewriteValueNode(
                        schemaName, arg.Type, variable.Value);
                    variables.Add(variable.WithValue(value));
                }
            }
        }