private void VerifyUsage(GraphQLOperationDefinition operation, VariableUsage usage, string opName)
        {
            var variableName = usage.Variable.Name.Value;

            if (!this.variableDefinitions.Contains(variableName))
            {
                this.Errors.Add(new GraphQLException(this.ComposeUndefinedVarMessage(variableName, opName),
                                                     new ASTNode[] { usage.Variable, operation }));
            }
        }
        private void VerifyUsage(VariableUsage usage)
        {
            var variableName = usage.Variable.Name.Value;

            if (this.variableDefinitions.ContainsKey(variableName))
            {
                var variableDefinition = this.variableDefinitions[variableName];
                var variableType       = this.GetInputType(this.variableDefinitions[variableName].Type);

                if (!TypeComparators.IsSubtypeOf(
                        this.GetEffectiveType(variableType, variableDefinition),
                        usage.ArgumentType,
                        this.SchemaRepository))
                {
                    this.Errors.Add(new GraphQLException(
                                        $"Variable \"${variableName}\" of type \"{variableType}\" used in " +
                                        $"position expecting type \"{usage.ArgumentType}\".",
                                        new ASTNode[] { variableDefinition, usage.Variable }));
                }
            }
        }
Ejemplo n.º 3
0
        // http://facebook.github.io/graphql/June2018/#IsVariableUsageAllowed()
        private bool IsVariableUsageAllowed(
            VariableDefinitionNode variableDefinition,
            VariableUsage variableUsage)
        {
            if (variableUsage.Type.IsNonNullType() &&
                !variableDefinition.Type.IsNonNullType())
            {
                if (variableDefinition.DefaultValue.IsNull() &&
                    variableUsage.InputField.DefaultValue.IsNull())
                {
                    return(false);
                }

                return(AreTypesCompatible(
                           variableDefinition.Type,
                           variableUsage.Type.NullableType()));
            }

            return(AreTypesCompatible(
                       variableDefinition.Type,
                       variableUsage.Type));
        }
 /// <summary>
 /// Initializes a new instance with the specified properties.
 /// </summary>
 public VariablesInAllowedPositionError(ValidationContext context, GraphQLVariableDefinition varDef, IGraphType varType, VariableUsage usage)
     : base(context.Document.Source, NUMBER, BadVarPosMessage(usage.Node.Name.StringValue, varType.ToString() !, usage.Type.ToString() !))
        /// <summary>
        /// Initializes a new instance with the specified properties.
        /// </summary>
        public VariablesInAllowedPositionError(ValidationContext context, VariableDefinition varDef, IGraphType varType, VariableUsage usage)
            : base(context.OriginalQuery, NUMBER, BadVarPosMessage(usage.Node.Name, context.Print(varType), context.Print(usage.Type)))
        {
            var varDefPos = new Location(context.OriginalQuery, varDef.SourceLocation.Start);
            var usagePos  = new Location(context.OriginalQuery, usage.Node.SourceLocation.Start);

            AddLocation(varDefPos.Line, varDefPos.Column);
            AddLocation(usagePos.Line, usagePos.Column);
        }
Ejemplo n.º 6
0
 public void AddVariableUsage(VariableUsage usage)
 => ValidationContext.AddListItem(nameof(GetVariablesVisitorContext), usage);
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance with the specified properties.
 /// </summary>
 public VariablesInAllowedPositionError(ValidationContext context, VariableDefinition varDef, IGraphType varType, VariableUsage usage)
     : base(context.Document.OriginalQuery !, NUMBER, BadVarPosMessage(usage.Node.Name, varType.ToString(), usage.Type.ToString()))