示例#1
0
        public void IsOutputType(INamedType type)
        {
            /* Given */
            /* When */
            var isOutput          = TypeIs.IsOutputType(type);
            var isOutputAsNonNull = TypeIs.IsOutputType(
                new NonNull(type));
            var isOutputAsList = TypeIs.IsOutputType(
                new List(type));

            /* Then */
            Assert.True(isOutput);
            Assert.True(isOutputAsNonNull);
            Assert.True(isOutputAsList);
        }
示例#2
0
    public TypeTracker(ISchema schema)
    {
        EnterOperationDefinition = node =>
        {
            var root = node.Operation switch
            {
                OperationType.Query => schema.Query,
                OperationType.Mutation => schema.Mutation,
                OperationType.Subscription => schema.Subscription,
                _ => throw new ArgumentOutOfRangeException()
            };

            Types.Push(root);
        };
        LeaveOperationDefinition = node => { Types.TryPop(out _); };

        EnterSelectionSet = node => { ParentTypes.Push(CurrentType); };


        LeaveSelectionSet = node => { ParentTypes.TryPop(out _); };

        EnterFieldSelection = node =>
        {
            if (ParentType is not null)
            {
                var fieldDefinition = schema.GetField(ParentType.Name, node.Name);
                FieldDefinitions.Push(fieldDefinition ?? null);

                if (fieldDefinition?.Type is not null)
                {
                    var fieldTypeDefinition = Ast.UnwrapAndResolveType(schema, fieldDefinition.Type);

                    if (fieldTypeDefinition is not null && TypeIs.IsOutputType(fieldTypeDefinition))
                    {
                        Types.Push(fieldTypeDefinition);
                    }
                    else
                    {
                        Types.Push(null);
                    }
                }
                else
                {
                    Types.Push(null);
                }
            }