示例#1
0
        public override void OnConfigure(
            IDescriptorContext context,
            IObjectTypeDescriptor descriptor,
            Type type)
        {
            var nodeDescriptor = new NodeDescriptor(descriptor, type);

            descriptor.Extend().OnBeforeCreate(definition =>
            {
                // since we bind the id field late we need to hint to the type discovery
                // that we will need the ID scalar.
                definition.Dependencies.Add(
                    TypeDependency.FromSchemaType(
                        context.TypeInspector.GetType(typeof(IdType))));
            });

            descriptor.Extend().OnBeforeCompletion((descriptorContext, definition) =>
            {
                // first we try to resolve the id field.
                if (IdField is not null)
                {
                    MemberInfo?idField = type.GetMember(IdField).FirstOrDefault();

                    if (idField is null)
                    {
                        throw NodeAttribute_IdFieldNotFound(type, IdField);
                    }

                    nodeDescriptor.IdField(idField);
                }
                else if (context.TypeInspector.GetNodeIdMember(type) is { } id)
                {
                    nodeDescriptor.IdField(id);
                }
示例#2
0
        public override void OnConfigure(
            IDescriptorContext context,
            IObjectTypeDescriptor descriptor,
            Type type)
        {
            INodeDescriptor nodeDescriptor = new NodeDescriptor(descriptor, type);

            if (IdField is not null)
            {
                MemberInfo?idField = type.GetMember(IdField).FirstOrDefault();

                if (idField is null)
                {
                    throw NodeAttribute_IdFieldNotFound(type, IdField);
                }

                nodeDescriptor.IdField(idField);
            }
            else if (context.TypeInspector.GetNodeIdMember(type) is { } id)
            {
                nodeDescriptor.IdField(id);
            }

            if (NodeResolverType is not null)
            {
                if (NodeResolver is not null)
                {
                    MethodInfo?method = NodeResolverType.GetMethod(NodeResolver);

                    if (method is null)
                    {
                        throw NodeAttribute_NodeResolverNotFound(
                                  NodeResolverType,
                                  NodeResolver);
                    }

                    nodeDescriptor.ResolveNodeWith(method);
                }
                else
                {
                    nodeDescriptor.ResolveNodeWith(NodeResolverType);
                }
            }
            else if (NodeResolver is not null)
            {
                MethodInfo?method = type.GetMethod(NodeResolver);

                if (method is null)
                {
                    throw NodeAttribute_NodeResolverNotFound(
                              type,
                              NodeResolver);
                }

                nodeDescriptor.ResolveNodeWith(method);
            }
            else
            {
                nodeDescriptor.ResolveNodeWith(type);
            }
        }