Exemple #1
0
        public void NamedType_ExtractType_ExtractSuccessfull(string fieldType)
        {
            // arrange
            ITypeNode type = GetType(fieldType);

            // act
            NamedTypeNode name = type.NamedType();

            // assert
            Assert.Equal("Foo", name.Print());
        }
Exemple #2
0
        public void InvalidTypeStructure()
        {
            // arrange
            ITypeNode type = GetType("[[[Foo!]!]!]!");

            // act
            Action a = () => type.NamedType();

            // assert
            Assert.Throws <NotSupportedException>(a);
        }
Exemple #3
0
 public SyntaxTypeReference(
     ITypeNode type,
     TypeContext context,
     string?scope = null,
     Func <IDescriptorContext, TypeSystemObjectBase>?factory = null)
     : base(
         factory is null ? TypeReferenceKind.Syntax : TypeReferenceKind.Factory,
         context,
         scope)
 {
     Type    = type ?? throw new ArgumentNullException(nameof(type));
     Name    = type.NamedType().Name.Value;
     Factory = factory;
 }
 private void SerializeListValue(
     ExportedVariable exported,
     ITypeNode type,
     ICollection <object?> list)
 {
     if (_requestExecutor.Schema.TryGetType(
             type.NamedType().Name.Value,
             out INamedInputType inputType))
     {
         SerializeListValue(exported, inputType, list);
     }
     else
     {
         throw BatchExecutor_CannotSerializeVariable(exported.Name);
     }
 }
            private object Serialize(ExportedVariable exported, ITypeNode type)
            {
                if (_requestExecutor.Schema.TryGetType(
                        type.NamedType().Name.Value,
                        out INamedInputType inputType) &&
                    _typeConverter.TryConvert(
                        typeof(object),
                        inputType.RuntimeType,
                        exported.Value,
                        out var converted))
                {
                    return(inputType.Serialize(converted));
                }

                throw BatchExecutor_CannotSerializeVariable(exported.Name);
            }
 private void SerializeListValue(
     ExportedVariable exported,
     ITypeNode type,
     ICollection <object> list)
 {
     if (_executor.Schema.TryGetType(
             type.NamedType().Name.Value,
             out INamedInputType inputType))
     {
         SerializeListValue(exported, inputType, list);
     }
     else
     {
         throw SerializationError();
     }
 }
        private object Serialize(ExportedVariable exported, ITypeNode type)
        {
            if (_executor.Schema.TryGetType(
                    type.NamedType().Name.Value,
                    out INamedInputType inputType) &&
                _typeConversion.TryConvert(
                    typeof(object),
                    inputType.ClrType,
                    exported.Value,
                    out var converted))
            {
                return(inputType.Serialize(converted));
            }

            throw SerializationError();
        }
        private IOutputType GetReturnType(
            MatchSelectionsContext context,
            FieldNode node,
            IOutputType type)
        {
            if (GetDirective(node, "_return") is DirectiveNode directive &&
                directive.Arguments.Count == 1 &&
                directive.Arguments[0] is { Name: { Value : "type" } } argument&&
                argument.Value is StringValueNode value)
            {
                ITypeNode     typeSyntax      = Utf8GraphQLParser.Syntax.ParseTypeReference(value.Value);
                NamedTypeNode namedTypeSyntax = typeSyntax.NamedType();
                var           named           = context.Schema.GetType <INamedOutputType>(namedTypeSyntax.Name.Value);
                return((IOutputType)typeSyntax.ToType(named));
            }

            return(type);
        }