public void FindUndeclaredVariablesFragmentDefinition()
        {
            // arrange
            ISchema schema = SchemaBuilder.New()
                             .AddStarWarsTypes()
                             .Create();

            DocumentNode document = Utf8GraphQLParser.Parse(
                @"
                query getHero {
                    ... q
                }

                fragment q on Query {
                    hero(episode: $ep) {
                        name
                    }
                }
                ");

            OperationDefinitionNode operation = document.Definitions
                                                .OfType <OperationDefinitionNode>()
                                                .First();

            var visitor       = new CollectVariablesVisitor(schema);
            var visitationMap = new CollectVariablesVisitationMap();

            visitationMap.Initialize(
                document.Definitions.OfType <FragmentDefinitionNode>()
                .ToDictionary(t => t.Name.Value));

            // act
            operation.Accept(
                visitor,
                visitationMap,
                node => VisitorAction.Continue);

            // assert
            var variables = operation.VariableDefinitions.ToList();

            variables.AddRange(visitor.VariableDeclarations);
            operation = operation.WithVariableDefinitions(variables);

            var definitions = new List <IDefinitionNode>();

            definitions.Add(operation);
            definitions.AddRange(
                document.Definitions.OfType <FragmentDefinitionNode>());

            QuerySyntaxSerializer.Serialize(
                new DocumentNode(
                    definitions)).MatchSnapshot();
        }
 public BatchExecutorEnumerable(
     IEnumerable <IReadOnlyQueryRequest> requestBatch,
     IRequestExecutor requestExecutor,
     IErrorHandler errorHandler,
     ITypeConverter typeConverter)
 {
     _requestBatch = requestBatch ??
                     throw new ArgumentNullException(nameof(requestBatch));
     _requestExecutor = requestExecutor ??
                        throw new ArgumentNullException(nameof(requestExecutor));
     _errorHandler = errorHandler ??
                     throw new ArgumentNullException(nameof(errorHandler));
     _typeConverter = typeConverter ??
                      throw new ArgumentNullException(nameof(typeConverter));
     _visitor = new CollectVariablesVisitor(requestExecutor.Schema);
 }
        public BatchQueryExecutionResult(
            IQueryExecutor executor,
            IErrorHandler errorHandler,
            ITypeConversion typeConversion,
            IReadOnlyList <IReadOnlyQueryRequest> batch)
        {
            _executor = executor
                        ?? throw new ArgumentNullException(nameof(executor));
            _errorHandler = errorHandler
                            ?? throw new ArgumentNullException(nameof(errorHandler));
            _typeConversion = typeConversion
                              ?? throw new ArgumentNullException(nameof(typeConversion));
            _batch = batch
                     ?? throw new ArgumentNullException(nameof(batch));

            _visitor = new CollectVariablesVisitor(executor.Schema);
        }
        public void FindUndeclaredVariablesInlineFragment()
        {
            // arrange
            ISchema schema = SchemaBuilder.New()
                             .AddStarWarsTypes()
                             .Create();

            DocumentNode document = Utf8GraphQLParser.Parse(
                @"
                query getHero {
                    ... on Query {
                        hero(episode: $ep) {
                            name
                        }
                    }
                }");

            OperationDefinitionNode operation = document.Definitions
                                                .OfType <OperationDefinitionNode>()
                                                .First();

            var visitor       = new CollectVariablesVisitor(schema);
            var visitationMap = new CollectVariablesVisitationMap();

            // act
            operation.Accept(
                visitor,
                visitationMap,
                node => VisitorAction.Continue);

            // assert
            var variables = operation.VariableDefinitions.ToList();

            variables.AddRange(visitor.VariableDeclarations);
            operation = operation.WithVariableDefinitions(variables);

            new DocumentNode(
                new IDefinitionNode[]
            {
                operation
            }).Print().MatchSnapshot();
        }