Beispiel #1
0
        public TypeDiscoveryContext(
            ITypeSystemObject type,
            TypeRegistry typeRegistry,
            TypeLookup typeLookup,
            IDescriptorContext descriptorContext,
            ITypeInterceptor typeInterceptor,
            string scope)
        {
            Type = type ??
                   throw new ArgumentNullException(nameof(type));
            _typeRegistry = typeRegistry ??
                            throw new ArgumentNullException(nameof(typeRegistry));
            _typeLookup = typeLookup ??
                          throw new ArgumentNullException(nameof(typeLookup));
            DescriptorContext = descriptorContext ??
                                throw new ArgumentNullException(nameof(descriptorContext));
            TypeInterceptor = typeInterceptor ??
                              throw new ArgumentNullException(nameof(typeInterceptor));
            Scope = scope;

            IsDirective = type is DirectiveType;
            IsSchema    = type is Schema;

            if (type is INamedType nt)
            {
                IsType = true;
                IsIntrospectionType = nt.IsIntrospectionType();
            }

            InternalName = "Type_" + Guid.NewGuid().ToString("N");
        }
        public TypeDiscoveryContext(
            ITypeSystemObject type,
            string scope,
            IServiceProvider services,
            IDescriptorContext descriptorContext,
            ITypeInterceptor interceptor)
        {
            Type = type
                   ?? throw new ArgumentNullException(nameof(type));
            Scope    = scope;
            Services = services
                       ?? throw new ArgumentNullException(nameof(services));
            DescriptorContext = descriptorContext
                                ?? throw new ArgumentNullException(nameof(descriptorContext));
            Interceptor = interceptor
                          ?? throw new ArgumentNullException(nameof(interceptor));
            IsDirective = type is DirectiveType;
            IsSchema    = type is Schema;

            if (type is INamedType nt)
            {
                IsType = true;
                IsIntrospectionType = nt.IsIntrospectionType();
            }

            InternalName = "Type_" + Guid.NewGuid().ToString("N");
        }
Beispiel #3
0
        public InitializationContext(
            ITypeSystemObject type,
            IServiceProvider services,
            IDescriptorContext descriptorContext,
            IDictionary <string, object> contextData)
        {
            Type = type
                   ?? throw new ArgumentNullException(nameof(type));
            Services = services
                       ?? throw new ArgumentNullException(nameof(services));
            _descriptorContext = descriptorContext
                                 ?? throw new ArgumentNullException(nameof(descriptorContext));
            ContextData = contextData
                          ?? throw new ArgumentNullException(nameof(contextData));

            IsDirective = type is DirectiveType;

            if (type is INamedType nt)
            {
                IsType = true;
                IsIntrospectionType = nt.IsIntrospectionType();
            }

            InternalName = "Type_" + Guid.NewGuid().ToString("N");
        }
 public static ISchemaError CompleteInterfacesHelper_UnableToResolveInterface(
     ITypeSystemObject interfaceOrObject,
     ISyntaxNode?node) =>
 SchemaErrorBuilder.New()
 .SetMessage("COULD NOT RESOLVE INTERFACE")
 .SetCode(ErrorCodes.Schema.MissingType)
 .SetTypeSystemObject(interfaceOrObject)
 .AddSyntaxNode(node)
 .Build();
Beispiel #5
0
 public static ISchemaError NoSchemaTypesAllowedAsRuntimeType(
     ITypeSystemObject type,
     Type runtimeType)
 => SchemaErrorBuilder.New()
 .SetMessage(
     TypeResources.ErrorHelper_NoSchemaTypesAllowedAsRuntimeType,
     type.Name,
     runtimeType.FullName ?? runtimeType.Name)
 .SetCode(ErrorCodes.Schema.NoSchemaTypesAllowedAsRuntimeType)
 .SetTypeSystemObject(type)
 .Build();
Beispiel #6
0
 public static ISchemaError MiddlewareOrderInvalid(
     FieldCoordinate field,
     ITypeSystemObject type,
     ISyntaxNode?syntaxNode,
     string currentOrder)
 => SchemaErrorBuilder.New()
 .SetMessage(TypeResources.ErrorHelper_MiddlewareOrderInvalid, field, currentOrder)
 .SetCode(ErrorCodes.Schema.MiddlewareOrderInvalid)
 .SetTypeSystemObject(type)
 .AddSyntaxNode(syntaxNode)
 .SetExtension(nameof(field), field)
 .Build();
 public static ISchemaError DirectiveCollection_DirectiveIsUnique(
     DirectiveType directiveType,
     ITypeSystemObject type,
     DirectiveNode?syntaxNode,
     object source) =>
 SchemaErrorBuilder.New()
 .SetMessage(
     TypeResources.DirectiveCollection_DirectiveIsUnique,
     directiveType.Name)
 .SetCode(ErrorCodes.Schema.MissingType)
 .SetTypeSystemObject(type)
 .AddSyntaxNode(syntaxNode)
 .SetExtension("Source", source)
 .Build();
Beispiel #8
0
 public static ISchemaError ObjectField_HasNoResolver(
     NameString typeName,
     NameString fieldName,
     ITypeSystemObject type,
     ISyntaxNode?syntaxNode) =>
 SchemaErrorBuilder.New()
 .SetMessage(
     TypeResources.ErrorHelper_ObjectField_HasNoResolver,
     typeName,
     fieldName)
 .SetCode(ErrorCodes.Schema.NoResolver)
 .SetTypeSystemObject(type)
 .AddSyntaxNode(syntaxNode)
 .Build();
 public static ISchemaError DirectiveCollection_ArgumentValueTypeIsWrong(
     DirectiveType directiveType,
     ITypeSystemObject type,
     DirectiveNode?syntaxNode,
     object source,
     string argumentName) =>
 SchemaErrorBuilder.New()
 .SetMessage(
     "The argument `{0}` value type is wrong.",
     argumentName)
 .SetCode(ErrorCodes.Schema.ArgumentValueTypeWrong)
 .SetTypeSystemObject(directiveType)
 .AddSyntaxNode(syntaxNode)
 .SetExtension("Source", source)
 .Build();
        public SchemaTypeReference(
            ITypeSystemObject type,
            bool?isTypeNullable,
            bool?isElementTypeNullable)
            : base(InferTypeContext(type),
                   isTypeNullable,
                   isElementTypeNullable)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            Type = type;
        }
 public static ISchemaError DirectiveCollection_LocationNotAllowed(
     DirectiveType directiveType,
     Types.DirectiveLocation location,
     ITypeSystemObject type,
     DirectiveNode?syntaxNode,
     object source) =>
 SchemaErrorBuilder.New()
 .SetMessage(
     TypeResources.DirectiveCollection_LocationNotAllowed,
     directiveType.Name,
     location)
 .SetCode(ErrorCodes.Schema.MissingType)
 .SetTypeSystemObject(type)
 .AddSyntaxNode(syntaxNode)
 .SetExtension("Source", source)
 .Build();
 public static ISchemaError  DirectiveCollection_ArgumentDoesNotExist(
     DirectiveType directiveType,
     ITypeSystemObject type,
     DirectiveNode?syntaxNode,
     object source,
     string argumentName) =>
 SchemaErrorBuilder.New()
 .SetMessage(
     "The argument `{0}` does not exist on the " +
     "directive `{1}`.",
     argumentName,
     directiveType.Name)
 .SetCode(ErrorCodes.Schema.InvalidArgument)
 .SetTypeSystemObject(type)
 .AddSyntaxNode(syntaxNode)
 .SetExtension("Source", source)
 .Build();
 public static ISchemaError DirectiveCollection_ArgumentNonNullViolation(
     DirectiveType directiveType,
     ITypeSystemObject type,
     DirectiveNode?syntaxNode,
     object source,
     string argumentName) =>
 SchemaErrorBuilder.New()
 .SetMessage(
     "The argument `{0}` of directive `{1}` " +
     "mustn't be null.",
     argumentName,
     directiveType.Name)
 .SetCode(ErrorCodes.Schema.NonNullArgument)
 .SetTypeSystemObject(type)
 .AddSyntaxNode(syntaxNode)
 .SetExtension("Source", source)
 .Build();
Beispiel #14
0
        public InitializationContext(
            ITypeSystemObject type,
            IServiceProvider services)
        {
            Type = type
                   ?? throw new ArgumentNullException(nameof(type));
            Services = services
                       ?? throw new ArgumentNullException(nameof(services));

            IsDirective = type is DirectiveType;

            if (type is INamedType nt)
            {
                IsType = true;
                IsIntrospectionType = nt.IsIntrospectionType();
            }

            InternalName = "Type_" + Guid.NewGuid().ToString("N");
        }
Beispiel #15
0
        public static void Complete(
            ICompletionContext context,
            IComplexOutputTypeDefinition definition,
            Type clrType,
            ICollection <InterfaceType> interfaces,
            ITypeSystemObject interfaceOrObject,
            ISyntaxNode?node)
        {
            if (clrType != typeof(object))
            {
                TryInferInterfaceUsageFromClrType(context, clrType, interfaces);
            }

            if (definition.KnownClrTypes.Count > 0)
            {
                definition.KnownClrTypes.Remove(typeof(object));

                foreach (Type type in definition.KnownClrTypes.Distinct())
                {
                    TryInferInterfaceUsageFromClrType(context, type, interfaces);
                }
            }

            foreach (ITypeReference interfaceRef in definition.Interfaces)
            {
                if (!context.TryGetType(interfaceRef, out InterfaceType type))
                {
                    // TODO : resources
                    context.ReportError(SchemaErrorBuilder.New()
                                        .SetMessage("COULD NOT RESOLVE INTERFACE")
                                        .SetCode(ErrorCodes.Schema.MissingType)
                                        .SetTypeSystemObject(interfaceOrObject)
                                        .AddSyntaxNode(node)
                                        .Build());
                }

                if (!interfaces.Contains(type))
                {
                    interfaces.Add(type);
                }
            }
        }
        public static void Complete(
            ITypeCompletionContext context,
            IComplexOutputTypeDefinition definition,
            Type clrType,
            ICollection <InterfaceType> interfaces,
            ITypeSystemObject interfaceOrObject,
            ISyntaxNode?node)
        {
            if (clrType != typeof(object))
            {
                TryInferInterfaceUsageFromClrType(context, clrType, interfaces);
            }

            if (definition.KnownClrTypes.Count > 0)
            {
                definition.KnownClrTypes.Remove(typeof(object));

                foreach (Type type in definition.KnownClrTypes.Distinct())
                {
                    TryInferInterfaceUsageFromClrType(context, type, interfaces);
                }
            }

            foreach (ITypeReference interfaceRef in definition.Interfaces)
            {
                if (!context.TryGetType(interfaceRef, out InterfaceType type))
                {
                    context.ReportError(
                        CompleteInterfacesHelper_UnableToResolveInterface(
                            interfaceOrObject, node));
                }

                if (!interfaces.Contains(type))
                {
                    interfaces.Add(type);
                }
            }
        }
Beispiel #17
0
        public static void CompleteInterfaces(
            ITypeCompletionContext context,
            IComplexOutputTypeDefinition definition,
            Type clrType,
            ICollection <InterfaceType> interfaces,
            ITypeSystemObject interfaceOrObject,
            ISyntaxNode?node)
        {
            foreach (ITypeReference interfaceRef in definition.Interfaces)
            {
                if (!context.TryGetType(interfaceRef, out InterfaceType type))
                {
                    context.ReportError(
                        CompleteInterfacesHelper_UnableToResolveInterface(
                            interfaceOrObject, node));
                }

                if (!interfaces.Contains(type))
                {
                    interfaces.Add(type);
                }
            }
        }
 public ISchemaErrorBuilder SetTypeSystemObject(
     ITypeSystemObject typeSystemObject)
 {
     _error.TypeSystemObject = typeSystemObject;
     return(this);
 }
 public SchemaTypeReference(ITypeSystemObject type)
     : this(type, null, null)
 {
 }
Beispiel #20
0
    private void ValidatePipeline(
        ITypeSystemObject type,
        FieldCoordinate field,
        ISyntaxNode?syntaxNode,
        IList <FieldMiddlewareDefinition> middlewareDefinitions)
    {
        var usePaging      = false;
        var useProjections = false;
        var useFiltering   = false;
        var useSorting     = false;
        var error          = false;

        foreach (FieldMiddlewareDefinition definition in middlewareDefinitions)
        {
            if (definition.Key is not null)
            {
                switch (definition.Key)
                {
                case WellKnownMiddleware.DbContext:
                    if (usePaging || useProjections || useFiltering || useSorting)
                    {
                        error = true;
                    }
                    break;

                case WellKnownMiddleware.Paging:
                    if (useProjections || useFiltering || useSorting)
                    {
                        error = true;
                        break;
                    }
                    usePaging = true;
                    break;

                case WellKnownMiddleware.Projection:
                    if (useFiltering || useSorting)
                    {
                        error = true;
                        break;
                    }
                    useProjections = true;
                    break;

                case WellKnownMiddleware.Filtering:
                    useFiltering = true;
                    break;

                case WellKnownMiddleware.Sorting:
                    useSorting = true;
                    break;
                }
            }
        }

        if (error)
        {
            throw new SchemaException(
                      ErrorHelper.MiddlewareOrderInvalid(
                          field,
                          type,
                          syntaxNode,
                          PrintPipeline(middlewareDefinitions)));
        }
    }