Esempio n. 1
0
 protected override void Configure(IObjectTypeDescriptor <Cat> descriptor)
 {
     descriptor.Interface <PetType>();
     descriptor.Interface <BeingType>();
     descriptor.Implements <MammalType>();
     descriptor.Field(t => t.Name).Type <NonNullType <StringType> >();
     descriptor.Field(t => t.DoesKnowCommand(default))
Esempio n. 2
0
        public static IObjectTypeDescriptor AsNode(
            this IObjectTypeDescriptor descriptor,
            Func <IServiceProvider, INodeResolver> nodeResolverFactory)
        {
            if (descriptor == null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

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

            descriptor
            .Interface <NodeType>()
            .Extend()
            .OnBeforeCreate(c =>
            {
                c.ContextData[RelayConstants.NodeResolverFactory] =
                    nodeResolverFactory;
            });

            return(descriptor);
        }
        protected override void Configure(
            IObjectTypeDescriptor <SomeOtherContract> descriptor)
        {
            descriptor
            .AsNode()
            .IdField(t => t.Id)
            .NodeResolver((ctx, id) =>
            {
                return(Task.FromResult(
                           ctx.Service <ContractStorage>()
                           .Contracts
                           .OfType <SomeOtherContract>()
                           .FirstOrDefault(t => t.Id.Equals(id))));
            });

            descriptor.Interface <ContractType>();

            descriptor.Field(t => t.Id)
            .Type <NonNullType <IdType> >();

            descriptor.Field(t => t.CustomerId)
            .Type <NonNullType <IdType> >();

            descriptor.Field(t => t.ExpiryDate)
            .Type <NonNullType <DateTimeType> >();
        }
Esempio n. 4
0
 protected override void Configure(
     IObjectTypeDescriptor <LifeInsuranceContract> descriptor)
 {
     descriptor.Interface <ContractType>();
     descriptor.Field(t => t.Id).Type <NonNullType <IdType> >();
     descriptor.Field(t => t.CustomerId).Ignore();
 }
Esempio n. 5
0
        protected override void Configure(
            IObjectTypeDescriptor <LifeInsuranceContract> descriptor)
        {
            descriptor
            .AsNode()
            .IdField(t => t.Id)
            .NodeResolver((ctx, id) =>
            {
                return(Task.FromResult(
                           ctx.Service <ContractStorage>()
                           .Contracts
                           .OfType <LifeInsuranceContract>()
                           .FirstOrDefault(t => t.Id.Equals(id))));
            });

            descriptor.Interface <ContractType>();
            descriptor.Field(t => t.Id).Type <NonNullType <IdType> >();
            descriptor.Field(t => t.CustomerId).Type <NonNullType <IdType> >();
            descriptor.Field("foo")
            .Argument("bar", a => a.Type <StringType>())
            .Resolver(ctx => ctx.ArgumentValue <string>("bar"));
            descriptor.Field("error")
            .Type <StringType>()
            .Resolver(ctx => ErrorBuilder.New()
                      .SetMessage("Error_Message")
                      .SetCode("ERROR_CODE")
                      .SetPath(ctx.Path)
                      .Build());
            descriptor.Field("date_field")
            .Type <DateType>()
            .Resolver(new DateTime(2018, 5, 17));
            descriptor.Field("date_time_field")
            .Type <DateTimeType>()
            .Resolver(new DateTime(
                          2018, 5, 17, 8, 59, 0,
                          DateTimeKind.Utc));
            descriptor.Field("string_field")
            .Type <StringType>()
            .Resolver("abc");
            descriptor.Field("id_field")
            .Type <IdType>()
            .Resolver("abc_123");
            descriptor.Field("byte_field")
            .Type <ByteType>()
            .Resolver(123);
            descriptor.Field("int_field")
            .Type <IntType>()
            .Resolver(123);
            descriptor.Field("long_field")
            .Type <LongType>()
            .Resolver(123);
            descriptor.Field("float_field")
            .Type <FloatType>()
            .Argument("f", a => a.Type <FloatType>())
            .Resolve(ctx => ctx.ArgumentValue <double?>("f") ?? 123.123);
            descriptor.Field("decimal_field")
            .Type <DecimalType>()
            .Resolver(123.123);
        }
Esempio n. 6
0
 protected override void Configure(IObjectTypeDescriptor <Human> descriptor)
 {
     descriptor.Interface <SentientType>();
     descriptor.Field(t => t.Name).Type <NonNullType <StringType> >();
     descriptor.Field("pets")
     .Type <ListType <PetType> >()
     .Resolver(() => "");
 }
 private static void DeclareInterfaces(
     IObjectTypeDescriptor typeDescriptor,
     IReadOnlyCollection <NamedTypeNode> interfaceReferences)
 {
     foreach (NamedTypeNode typeNode in interfaceReferences)
     {
         typeDescriptor.Interface(typeNode);
     }
 }
Esempio n. 8
0
 protected override void Configure(IObjectTypeDescriptor descriptor)
 {
     descriptor.Name("Tea");
     descriptor.Interface <DrinkType>();
     descriptor.Field("kind")
     .Type <NonNullType <DrinkKindType> >()
     .Resolver(() => DrinkKind.BlackTea);
     descriptor.IsOfType((c, obj) => obj.Equals("black_tea"));
 }
Esempio n. 9
0
        protected override void Configure(IObjectTypeDescriptor <Droid> descriptor)
        {
            descriptor.Interface <CharacterType>();

            descriptor.Field(t => t.Id).Type <NonNullType <StringType> >();

            descriptor.Field(t => t.AppearsIn).Type <ListType <EpisodeType> >();

            descriptor.Field <CommonResolvers>(r => r.GetCharacter(default, default))
 protected override void Configure(
     IObjectTypeDescriptor <LifeInsuranceContract> descriptor)
 {
     descriptor.Interface <ContractType>();
     descriptor.Field(t => t.Id).Type <NonNullType <IdType> >();
     descriptor.Field(t => t.CustomerId).Type <NonNullType <IdType> >();
     descriptor.Field("foo")
     .Argument("bar", a => a.Type <StringType>())
     .Resolver(ctx => ctx.Argument <string>("bar"));
 }
Esempio n. 11
0
        protected override void Configure(IObjectTypeDescriptor <Team> descriptor)
        {
            descriptor.Name("Team");

            descriptor.Interface <BaseEntityType <Team> >();

            descriptor.Field(t => t.Id).Type <NonNullType <UuidType> >();

            descriptor.Field(t => t.Creator).Ignore();
            descriptor.Field <BaseResolver <Account> >(t => t.GetCreator(default, default));
Esempio n. 12
0
 protected override void Configure(IObjectTypeDescriptor <Droid> descriptor)
 {
     descriptor.Interface <CharacterType>();
     descriptor.Field(t => t.Friends)
     .Type <ListType <CharacterType> >()
     .Resolver(c => CharacterType.GetCharacter(c));
     descriptor.Field(t => t.Height)
     .Argument("unit", a => a.Type <EnumType <Unit> >())
     .Resolver(c => CharacterType.GetHeight(c));
 }
Esempio n. 13
0
        protected override void Configure(IObjectTypeDescriptor <Human> descriptor)
        {
            descriptor.Interface <CharacterType>();

            descriptor.Field(t => t.Id)
            .Type <NonNullType <IdType> >();

            descriptor.Field(t => t.AppearsIn)
            .Type <ListType <EpisodeType> >();

            descriptor.Field <SharedResolvers>(r => r.GetCharacterAsync(default, default))
Esempio n. 14
0
        protected override void Configure(IObjectTypeDescriptor <IInputDevice> descriptor)
        {
            descriptor.Name("InputDevice");
            descriptor.Interface <NodeType>();

            descriptor
            .ImplementsNode()
            .IdField(t => t.InstanceGuid)
            .ResolveNode((ctx, id) => Task.FromResult(
                             ctx.SnowflakeService <IDeviceEnumerator>().QueryConnectedDevices().FirstOrDefault(i => i.InstanceGuid == id)));
        }
Esempio n. 15
0
        protected override void Configure(IObjectTypeDescriptor <IGame> descriptor)
        {
            descriptor.ExtendGame();
            descriptor.Interface <NodeType>();
            descriptor.Field("id")
            .Type <IdType>()
            .Resolver(ctx => ctx.Parent <IGame>().Record.RecordID);

            descriptor.AsNode()
            .NodeResolver <Guid>(async(ctx, id) => await ctx.SnowflakeService <IGameLibrary>().GetGameAsync(id));
        }
        protected override void Configure(IObjectTypeDescriptor <IPlatformInfo> descriptor)
        {
            descriptor.Name("PlatformInfo");
            descriptor.Interface <NodeType>();
            descriptor.Field("id")
            .Type <IdType>()
            .Resolver(ctx => ctx.Parent <IPlatformInfo>().PlatformID);

            descriptor.AsNode()
            .NodeResolver <PlatformId>((ctx, id) => Task.FromResult(
                                           ctx.SnowflakeService <IStoneProvider>().Platforms.TryGetValue(id, out var value) ? value : null));
        }
Esempio n. 17
0
        protected override void Configure(IObjectTypeDescriptor <IInputDevice> descriptor)
        {
            descriptor.Name("InputDevice");
            descriptor.Interface <NodeType>();
            descriptor.Field("id")
            .Type <IdType>()
            .Resolver(ctx => ctx.Parent <IInputDevice>().InstanceGuid);

            descriptor.AsNode()
            .NodeResolver <Guid>((ctx, id) =>
                                 Task.FromResult(
                                     ctx.SnowflakeService <IDeviceEnumerator>().QueryConnectedDevices().FirstOrDefault(i => i.InstanceGuid == id)));
        }
        protected override void Configure(IObjectTypeDescriptor <IControllerLayout> descriptor)
        {
            descriptor.Name("ControllerLayout");
            descriptor.Interface <NodeType>();
            descriptor.Field("id")
            .Type <IdType>()
            .Resolve(ctx => ctx.Parent <IControllerLayout>().ControllerID);

            descriptor
            .ImplementsNode()
            .ResolveNode <string>((ctx, id) => Task.FromResult <object>(
                                      ctx.SnowflakeService <IStoneProvider>().Controllers.TryGetValue(id, out var value) ? value : null));
        }
Esempio n. 19
0
        protected override void Configure(
            IObjectTypeDescriptor <SomeOtherContract> descriptor)
        {
            descriptor.Interface <ContractType>();

            descriptor.Field(t => t.Id)
            .Type <NonNullType <IdType> >();

            descriptor.Field(t => t.CustomerId)
            .Ignore();

            descriptor.Field(t => t.ExpiryDate)
            .Type <NonNullType <DateTimeType> >();
        }
 protected override void Configure(
     IObjectTypeDescriptor <LifeInsuranceContract> descriptor)
 {
     descriptor.Interface <ContractType>();
     descriptor.Field(t => t.Id).Type <NonNullType <IdType> >();
     descriptor.Field(t => t.CustomerId).Type <NonNullType <IdType> >();
     descriptor.Field("foo")
     .Argument("bar", a => a.Type <StringType>())
     .Resolver(ctx => ctx.Argument <string>("bar"));
     descriptor.Field("error")
     .Type <StringType>()
     .Resolver(ctx => ErrorBuilder.New()
               .SetMessage("Error_Message")
               .SetCode("ERROR_CODE")
               .SetPath(ctx.Path)
               .Build());
     descriptor.Field("date_field")
     .Type <DateType>()
     .Resolver(new DateTime(2018, 5, 17));
     descriptor.Field("date_time_field")
     .Type <DateTimeType>()
     .Resolver(new DateTime(
                   2018, 5, 17, 8, 59, 0,
                   DateTimeKind.Utc));
     descriptor.Field("string_field")
     .Type <StringType>()
     .Resolver("abc");
     descriptor.Field("id_field")
     .Type <IdType>()
     .Resolver("abc_123");
     descriptor.Field("byte_field")
     .Type <ByteType>()
     .Resolver(123);
     descriptor.Field("int_field")
     .Type <IntType>()
     .Resolver(123);
     descriptor.Field("long_field")
     .Type <LongType>()
     .Resolver(123);
     descriptor.Field("float_field")
     .Type <FloatType>()
     .Resolver(123.123);
     descriptor.Field("decimal_field")
     .Type <DecimalType>()
     .Resolver(123.123);
 }
 protected override void Configure(
     IObjectTypeDescriptor <LifeInsuranceContract> descriptor)
 {
     descriptor.Interface <ContractType>();
     descriptor.Field(t => t.Id).Type <NonNullType <IdType> >();
     descriptor.Field(t => t.CustomerId).Type <NonNullType <IdType> >();
     descriptor.Field("foo")
     .Argument("bar", a => a.Type <StringType>())
     .Resolver(ctx => ctx.Argument <string>("bar"));
     descriptor.Field("error")
     .Type <StringType>()
     .Resolver(ctx => ErrorBuilder.New()
               .SetMessage("Error_Message")
               .SetCode("ERROR_CODE")
               .SetPath(ctx.Path)
               .Build());
 }
        public IObjectFieldDescriptor NodeResolver(
            NodeResolverDelegate <TNode, TId> nodeResolver)
        {
            Func <IServiceProvider, INodeResolver> nodeResolverFactory =
                services => new NodeResolver <TNode, TId>(nodeResolver);

            _typeDescriptor
            .Interface <NodeType>()
            .Extend()
            .OnBeforeCreate(c =>
            {
                c.ContextData[RelayConstants.NodeResolverFactory] =
                    nodeResolverFactory;
            });

            return(_typeDescriptor.Field(_propertyOrMethod)
                   .Type <NonNullType <IdType> >());
        }
Esempio n. 23
0
        protected override void Configure(IObjectTypeDescriptor <TaskResult <T> > descriptor)
        {
            descriptor
            .Interface <TaskResultTypeInterface>()
            .Extend()
            .OnBeforeNaming((completionContext, definition) =>
            {
                var valueTypeReference = definition.Fields.First(f => f.Name == "value").Type;
                var unionType          = completionContext.GetType <TaskResultErrorUnionType <TType> >(valueTypeReference);
                string unionTypeName   = unionType.Name.ToString();
                // Nasty hack that relies on the union value being TaskResultValue.
                // I would have liked to do this properly but types are not populated early enough
                // for the union type.
                var dependentName      = unionTypeName.Substring(0, unionTypeName.Length - "TaskResultValue".Length);
                definition.Name        = $"{dependentName}TaskResult";
                definition.Description = $"Describes a task result that yields {dependentName}";
            })
            .DependsOn <TaskResultErrorUnionType <TType> >(true)
            .DependsOn <TType>(true);

            descriptor.Field("description")
            .Description("Describes this task result in a human-friendly way.")
            .Resolver(async ctx => await(ctx.Parent <TaskResult <T> >().Description))
            .Type <StringType>();
            descriptor.Field(t => t.Name)
            .Description("The name of this task result.")
            .Type <StringType>();
            descriptor.Field("errored")
            .Description("Whether or not this task has errored.")
            .Resolver(ctx => ctx.Parent <TaskResult <T> >().Error != null)
            .Type <NonNullType <BooleanType> >();
            descriptor.Field("value")
            .Resolver(async ctx =>
            {
                var taskResult = ctx.Parent <TaskResult <T> >();
                // lol if err != nil
                if (taskResult.Error != null)
                {
                    return(taskResult.Error);
                }
                return(await taskResult);
            })
            .Type <TaskResultErrorUnionType <TType> >();
        }
Esempio n. 24
0
        /// <summary>
        /// Implements fields and interfaces for AsyncJobQueue object types.
        /// The job field must still be manually specified by the client.
        /// </summary>
        /// <typeparam name="T">The type of the job queue.</typeparam>
        /// <param name="descriptor">The GraphQL Type descriptor.</param>
        /// <returns>The GraphQL type descriptor.</returns>
        public static IObjectTypeDescriptor <T> UseJobQueue <T>(this IObjectTypeDescriptor <T> descriptor)
            where T : class, IAsyncJobQueue
        {
            descriptor
            .Interface <JobQueueInterface>();

            descriptor.Field(s => s.GetActiveJobs())
            .Name("activeJobIds")
            .Description("The jobs currently active in the scraping queue.")
            .Type <NonNullType <ListType <NonNullType <UuidType> > > >();
            descriptor.Field(s => s.GetQueuedJobs())
            .Name("queuedJobIds")
            .Description("The jobs currently in the scraping queue.")
            .Type <NonNullType <ListType <NonNullType <UuidType> > > >();
            descriptor.Field(s => s.GetZombieJobs())
            .Name("zombieJobIds")
            .Description("The jobs that are still in the scraping queue, but no longer has items to process.")
            .Type <NonNullType <ListType <NonNullType <UuidType> > > >();
            return(descriptor);
        }
Esempio n. 25
0
        protected override void Configure(IObjectTypeDescriptor <Account> descriptor)
        {
            descriptor.Name("Account");

            descriptor.Interface <BaseEntityType <Account> >();

            descriptor.Field(t => t.AccountGroupIds).Ignore();
            descriptor.Field(t => t.AccountGroups).Ignore();
            descriptor.Field(t => t.AccountTeamIds).Ignore();
            descriptor.Field(t => t.AccountTeams).Ignore();
            // descriptor.Field(t=>t.UserId).Ignore();
            descriptor.Field(t => t.CreatorId).Ignore();
            descriptor.Field(t => t.ModifierId).Ignore();

            // descriptor.Field(t=>t.Role).Ignore();

            descriptor.Field(t => t.Id).Type <NonNullType <UuidType> >();

            descriptor.Field(t => t.Creator).Ignore();
            descriptor.Field <BaseResolver <Account> >(t => t.GetCreator(default, default));
 protected override void Configure(
     IObjectTypeDescriptor <Foo> descriptor)
 {
     descriptor.Interface <FooInterfaceType>();
     descriptor.Field(t => t.Bar).UsePaging <StringType>();
 }
Esempio n. 27
0
 protected override void Configure(IObjectTypeDescriptor <Xyz> descriptor)
 {
     descriptor.Interface <AlphabeticalInterfaceType>();
 }
Esempio n. 28
0
 protected override void Configure(IObjectTypeDescriptor <Alien> descriptor)
 {
     descriptor.Interface <SentientType>();
     descriptor.Field(t => t.Name).Type <NonNullType <StringType> >();
 }