Example #1
0
        public ObjectType Create(IDescriptorContext context, ObjectTypeDefinitionNode node)
        {
            var preserveSyntaxNodes = context.Options.PreserveSyntaxNodes;

            var typeDefinition = new ObjectTypeDefinition(
                node.Name.Value,
                node.Description?.Value);

            typeDefinition.BindTo = node.GetBindingValue();

            if (preserveSyntaxNodes)
            {
                typeDefinition.SyntaxNode = node;
            }

            foreach (NamedTypeNode typeNode in node.Interfaces)
            {
                typeDefinition.Interfaces.Add(TypeReference.Create(typeNode));
            }

            SdlToTypeSystemHelper.AddDirectives(typeDefinition, node);

            DeclareFields(typeDefinition, node.Fields, preserveSyntaxNodes);

            return(ObjectType.CreateUnsafe(typeDefinition));
        }
Example #2
0
        private static void DeclareFields(
            ObjectTypeDefinition parent,
            IReadOnlyCollection <FieldDefinitionNode> fields,
            bool preserveSyntaxNodes)
        {
            foreach (FieldDefinitionNode field in fields)
            {
                var fieldDefinition = new ObjectFieldDefinition(
                    field.Name.Value,
                    field.Description?.Value,
                    TypeReference.Create(field.Type));
                fieldDefinition.BindTo = field.GetBindingValue();

                if (preserveSyntaxNodes)
                {
                    fieldDefinition.SyntaxNode = field;
                }

                SdlToTypeSystemHelper.AddDirectives(fieldDefinition, field);

                if (field.DeprecationReason() is { Length: > 0 } reason)
                {
                    fieldDefinition.DeprecationReason = reason;
                }

                DeclareFieldArguments(fieldDefinition, field, preserveSyntaxNodes);

                parent.Fields.Add(fieldDefinition);
            }
        }
    public static void CollectDependencies(
        ObjectTypeDefinition definition,
        ICollection <TypeDependency> dependencies)
    {
        if (definition is null)
        {
            throw new ArgumentNullException(nameof(definition));
        }

        if (dependencies is null)
        {
            throw new ArgumentNullException(nameof(dependencies));
        }

        if (definition.HasDependencies)
        {
            foreach (TypeDependency dependency in definition.Dependencies)
            {
                dependencies.Add(dependency);
            }
        }

        if (definition.HasInterfaces)
        {
            foreach (ITypeReference typeRef in definition.Interfaces)
            {
                dependencies.Add(new(typeRef, TypeDependencyKind.Completed));
            }
        }

        CollectDirectiveDependencies(definition, dependencies);
        CollectFieldDependencies(definition.Fields, dependencies);
    }
Example #4
0
 internal void OnCompleteDefinition(ObjectTypeDefinition definition)
 {
     if (Definition.Resolver is not null)
     {
         definition.ContextData[WellKnownContextData.NodeResolver] = Definition.Resolver;
     }
 }
Example #5
0
 protected override void OnRegisterDependencies(
     ITypeDiscoveryContext context,
     ObjectTypeDefinition definition)
 {
     base.OnRegisterDependencies(context, definition);
     context.Dependencies.Add(new(context.TypeInspector.GetTypeRef(typeof(T))));
 }
 protected internal ObjectTypeDescriptor(
     IDescriptorContext context,
     ObjectTypeDefinition definition)
     : base(context, definition)
 {
     Definition = definition;
 }
        public static void RegisterDependencies(
            this IInitializationContext context,
            ObjectTypeDefinition definition)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (definition == null)
            {
                throw new ArgumentNullException(nameof(definition));
            }

            context.RegisterDependencyRange(
                definition.Interfaces,
                TypeDependencyKind.Default);

            RegisterDirectiveDependencies(context, definition);
            RegisterFieldDependencies(context, definition.Fields);

            foreach (ObjectFieldDefinition field in definition.Fields)
            {
                if (field.Member != null)
                {
                    context.RegisterResolver(
                        field.Name,
                        field.Member,
                        definition.ClrType,
                        field.ResolverType);
                }
            }
        }
Example #8
0
 private void OnCompleteDefinition(ObjectTypeDefinition definition)
 {
     if (Definition.Resolver is not null)
     {
         definition.ContextData[WellKnownContextData.EntityResolver] = Definition.Resolver;
     }
 }
Example #9
0
        public static void RegisterDependencies(
            this ITypeDiscoveryContext context,
            ObjectTypeDefinition definition)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (definition == null)
            {
                throw new ArgumentNullException(nameof(definition));
            }

            context.RegisterDependencyRange(
                definition.Interfaces,
                TypeDependencyKind.Default);

            RegisterAdditionalDependencies(context, definition);
            RegisterDirectiveDependencies(context, definition);
            RegisterFieldDependencies(context, definition.Fields);

            foreach (ObjectFieldDefinition field in definition.Fields)
            {
                if (field.Resolver is null)
                {
                    if (field.ResolverMember is { })
 protected override void OnRegisterDependencies(
     ITypeDiscoveryContext context,
     ObjectTypeDefinition definition)
 {
     base.OnRegisterDependencies(context, definition);
     context.RegisterDependencies(definition);
     SetTypeIdentity(typeof(ObjectType <>));
 }
Example #11
0
        private async Task <ISearchResultCollection> GetResources(string Filter, string ObjectType)
        {
            ObjectTypeDefinition objectType = ResourceManagementSchema.GetObjectType(ObjectType);
            var attributes = objectType.Attributes.Select(t => t.SystemName);

            return(await Task.FromResult <ISearchResultCollection>(
                       RmcWrapper.Client.GetResourcesAsync(Filter, attributes)));
        }
        protected override void ProcessRecord()
        {
            CultureInfo locale = null;

            if (this.Locale != null)
            {
                locale = new CultureInfo(this.Locale);
            }

            IEnumerable <string> attributes = null;
            string filter = this.GetQueryString();

            if (!this.Unconstrained.IsPresent)
            {
                if (this.AttributesToGet == null || this.AttributesToGet.Length == 0)
                {
                    if (string.IsNullOrWhiteSpace(this.ExpectedObjectType))
                    {
                        attributes = new List <string>()
                        {
                            "ObjectID"
                        };
                    }
                    else
                    {
                        ObjectTypeDefinition objectType = ResourceManagementSchema.GetObjectType(this.ExpectedObjectType);
                        attributes = objectType.Attributes.Select(t => t.SystemName);
                    }
                }
                else
                {
                    attributes = this.AttributesToGet;
                }
            }

            int pageSize;

            if (this.PageSize > 0)
            {
                pageSize = this.PageSize;
            }
            else
            {
                pageSize = 200;
            }

            List <SortingAttribute> sortCriteria = new List <SortingAttribute>();

            if (this.SortAttributes != null)
            {
                foreach (string attribute in this.SortAttributes)
                {
                    sortCriteria.Add(new SortingAttribute(attribute, !this.Descending));
                }
            }

            this.WriteObject(new RmaSearchPager(RmcWrapper.Client.GetResourcesPaged(filter, pageSize, attributes, sortCriteria, locale)));
        }
 public TypeInfo(
     ITypeCompletionContext context,
     ObjectType type,
     ObjectTypeDefinition definition)
 {
     Context    = context;
     Type       = type;
     Definition = definition;
 }
Example #14
0
        protected override void OnCompleteType(
            ITypeCompletionContext context,
            ObjectTypeDefinition definition)
        {
            base.OnCompleteType(context, definition);

            EdgeType = context.GetType <EdgeType <T> >(
                context.TypeInspector.GetTypeRef(typeof(EdgeType <T>)));
        }
Example #15
0
        protected override void OnCompleteType(
            ITypeCompletionContext context,
            ObjectTypeDefinition definition)
        {
            base.OnCompleteType(context, definition);

            EntityType = context.GetType <IOutputType>(
                TypeReference.Create <T>());
        }
Example #16
0
        protected override void OnCompleteType(
            ITypeCompletionContext context,
            ObjectTypeDefinition definition)
        {
            base.OnCompleteType(context, definition);

            ItemType = context.GetType <IOutputType>(
                context.TypeInspector.GetTypeRef(typeof(T)));
        }
Example #17
0
        protected override void OnCompleteType(
            ICompletionContext context,
            ObjectTypeDefinition definition)
        {
            base.OnCompleteType(context, definition);

            EdgeType = context.GetType <EdgeType <T> >(
                ClrTypeReference.FromSchemaType <EdgeType <T> >());
        }
Example #18
0
        protected override void OnCompleteType(
            ICompletionContext context,
            ObjectTypeDefinition definition)
        {
            base.OnCompleteType(context, definition);

            EdgeType = context.GetType <EdgeType <T> >(
                new ClrTypeReference(typeof(EdgeType <T>),
                                     TypeContext.Output));
        }
Example #19
0
        protected override void OnRegisterDependencies(
            ITypeDiscoveryContext context,
            ObjectTypeDefinition definition)
        {
            base.OnRegisterDependencies(context, definition);

            context.RegisterDependency(
                TypeReference.Create <EdgeType <T> >(),
                TypeDependencyKind.Default);
        }
Example #20
0
        protected override void OnRegisterDependencies(
            IInitializationContext context,
            ObjectTypeDefinition definition)
        {
            base.OnRegisterDependencies(context, definition);

            context.RegisterDependency(
                ClrTypeReference.FromSchemaType <EdgeType <T> >(),
                TypeDependencyKind.Default);
        }
Example #21
0
        protected override void OnRegisterDependencies(
            ITypeDiscoveryContext context,
            ObjectTypeDefinition definition)
        {
            base.OnRegisterDependencies(context, definition);

            context.RegisterDependency(
                context.TypeInspector.GetTypeRef(typeof(EdgeType <T>)),
                TypeDependencyKind.Default);
        }
Example #22
0
        protected override void OnCompleteName(
            ICompletionContext context,
            ObjectTypeDefinition definition)
        {
            base.OnCompleteName(context, definition);

            INamedType namedType = context.GetType <INamedType>(
                new ClrTypeReference(typeof(T), TypeContext.Output));

            Name = namedType.Name + "Edge";
        }
        public static void RegisterDependencies(
            this ITypeDiscoveryContext context,
            ObjectTypeDefinition definition)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (definition is null)
            {
                throw new ArgumentNullException(nameof(definition));
            }

            context.RegisterDependencyRange(
                definition.GetInterfaces(),
                TypeDependencyKind.Completed);

            RegisterAdditionalDependencies(context, definition);
            RegisterDirectiveDependencies(context, definition);
            RegisterFieldDependencies(context, definition.Fields);

            foreach (ObjectFieldDefinition field in definition.Fields)
            {
                if (field.Resolver is null)
                {
                    if (field.Expression is not null)
                    {
                        context.RegisterResolver(
                            field.Name,
                            field.Expression,
                            definition.RuntimeType,
                            field.ResolverType);
                    }
                    else if (field.ResolverMember is not null)
                    {
                        context.RegisterResolver(
                            field.Name,
                            field.ResolverMember,
                            definition.RuntimeType,
                            field.ResolverType);
                    }
                    else if (field.Member is not null)
                    {
                        context.RegisterResolver(
                            field.Name,
                            field.Member,
                            definition.RuntimeType,
                            field.ResolverType);
                    }
                }
            }
        }
Example #24
0
        protected override void OnRegisterDependencies(
            IInitializationContext context,
            ObjectTypeDefinition definition)
        {
            base.OnRegisterDependencies(context, definition);

            context.RegisterDependency(
                new ClrTypeReference(
                    typeof(T),
                    TypeContext.Output),
                TypeDependencyKind.Named);
        }
        private void OnCompleteDefinition(ObjectTypeDefinition definition)
        {
            if (Definition.Resolver is null)
            {
                ResolveNodeWith <TNode>();
            }

            if (Definition.Resolver is not null)
            {
                definition.ContextData[WellKnownContextData.NodeResolver] =
                    Definition.Resolver;
            }
        }
Example #26
0
 public IEnumerable <ITypeDeclaration> GetTypeDeclarations()
 {
     return(document.Children.Concat(options.ScalarTypes).Select(def => def switch
     {
         ObjectTypeDefinition objectTypeDefinition => new ObjectTypeContext(objectTypeDefinition, options, document) as ITypeDeclaration,
         InputObjectTypeDefinition inputObjectTypeDefinition => new InputObjectTypeContext(inputObjectTypeDefinition, options, document) as ITypeDeclaration,
         InterfaceTypeDefinition interfaceTypeDefinition => new InterfaceTypeContext(interfaceTypeDefinition, options, document) as ITypeDeclaration,
         EnumTypeDefinition enumTypeDefinition => new EnumTypeContext(enumTypeDefinition, options, document) as ITypeDeclaration,
         UnionTypeDefinition unionTypeDefinition => new UnionTypeContext(unionTypeDefinition, options) as ITypeDeclaration,
         ScalarTypeDefinition scalarTypeDefinition => new ScalarTypeContext(scalarTypeDefinition, options) as ITypeDeclaration,
         SchemaDefinition _ => null,
         _ => throw new InvalidOperationException("Unhandled definition type " + def.Kind.ToString("g"))
     })
Example #27
0
 public static Exception ArgumentTypeNameMissMatch(
     ObjectTypeDefinition objectTypeDefinition,
     string generatedArgumentName,
     ObjectFieldDefinition fieldDefinition,
     string currentTypeName,
     string collidingTypeName) =>
 new SchemaException(SchemaErrorBuilder.New()
                     .SetMessage(
                         MutationResources.ThrowHelper_InputMiddleware_ArgumentTypeNameMissMatch,
                         generatedArgumentName,
                         $"{objectTypeDefinition.Name}.{fieldDefinition.Name}",
                         currentTypeName,
                         collidingTypeName,
                         objectTypeDefinition.Name)
                     .Build());
    protected override void OnCompleteType(
        ITypeCompletionContext context,
        ObjectTypeDefinition definition)
    {
        base.OnCompleteType(context, definition);

        if (ValidateFields(context, definition))
        {
            _isOfType   = definition.IsOfType;
            SyntaxNode  = definition.SyntaxNode;
            Fields      = OnCompleteFields(context, definition);
            _implements = CompleteInterfaces(context, definition.GetInterfaces(), this);
            CompleteTypeResolver(context);
        }
    }
    public static void RegisterDependencies(
        this ITypeDiscoveryContext context,
        ObjectTypeDefinition definition)
    {
        if (context is null)
        {
            throw new ArgumentNullException(nameof(context));
        }

        if (definition is null)
        {
            throw new ArgumentNullException(nameof(definition));
        }

        CollectDependencies(definition, context.Dependencies);
    }
Example #30
0
    private void RewriteMessageFieldToNonNullableStringType(
        IDescriptorContext context,
        ObjectTypeDefinition definition)
    {
        // if a user provides his/her own error interface we will not rewrite the message type
        // and the user is responsible for ensuring that type and interface align.
        if (context.ContextData.ContainsKey(ErrorContextData.ErrorType))
        {
            return;
        }

        // if the error interface is the standard error interface it must provide a message
        // filed.
        if (definition.Fields.FirstOrDefault(f => f.Name == "message") is not {
        } messageField)
        {
            throw ThrowHelper.MessageWasNotDefinedOnError(this, definition.RuntimeType);
        }

        // we will ensure that the error message type is correct.
        messageField.Type = TypeReference.Parse("String!");
    }