コード例 #1
0
 protected override void Configure(IObjectTypeDescriptor <User> descriptor)
 {
     base.Configure(descriptor);
     descriptor.AsNode()
     .IdField(u => u.Id)
     .NodeResolver(ResolveUser);
 }
コード例 #2
0
        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.Implements <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> >();
        }
コード例 #3
0
 protected override void Configure(IObjectTypeDescriptor <Client> descriptor)
 {
     descriptor.AsNode()
     .IdField(t => t.Id)
     .NodeResolver((context, id) =>
                   context.DataLoader <ClientByIdDataLoader>().LoadAsync(id, context.RequestAborted));
 }
コード例 #4
0
 protected override void Configure(IObjectTypeDescriptor <Demand> descriptor)
 {
     base.Configure(descriptor);
     descriptor.AsNode()
     .IdField(d => d.Id)
     .NodeResolver(ResolveDemand);
 }
コード例 #5
0
 protected override void Configure(IObjectTypeDescriptor <Product> descriptor)
 {
     base.Configure(descriptor);
     descriptor.AsNode()
     .IdField(p => p.Id)
     .NodeResolver(ResolveProduct);
 }
コード例 #6
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);
        }
コード例 #7
0
 protected override void Configure(
     IObjectTypeDescriptor <Entity> descriptor)
 {
     descriptor.AsNode <Entity, string>(
         (ctx, id) => Task.FromResult(new Entity {
         Name = id
     }));
     descriptor.Field(t => t.Id).Type <NonNullType <IdType> >();
 }
コード例 #8
0
        protected override void Configure(IObjectTypeDescriptor <SchemaVersion> descriptor)
        {
            descriptor.AsNode()
            .IdField(t => t.Id)
            .NodeResolver((context, id) =>
                          context.DataLoader <SchemaVersionByIdDataLoader>()
                          .LoadAsync(id, context.RequestAborted));

            descriptor.Ignore(t => t.SchemaId);
        }
コード例 #9
0
        protected override void Configure(IObjectTypeDescriptor <Session> descriptor)
        {
            descriptor
            .AsNode()
            .IdField(t => t.Id)
            .NodeResolver((ctx, id) => ctx.DataLoader <SessionByIdDataLoader>().LoadAsync(id, ctx.RequestAborted));

            descriptor
            .Field(t => t.SessionSpeakers)
            .ResolveWith <SessionResolvers>(t => t.GetSpeakersAsync(default !, default !, default !, default))
コード例 #10
0
 protected override void Configure(
     IObjectTypeDescriptor <Entity> descriptor)
 {
     descriptor.AsNode()
     .IdField(t => t.Id)
     .NodeResolver((ctx, id) =>
                   Task.FromResult(new Entity {
         Name = id
     }));
 }
コード例 #11
0
ファイル: DummyNodeType.cs プロジェクト: Krashner/snowflake
 protected override void Configure(IObjectTypeDescriptor descriptor)
 {
     descriptor.Name("_DummyNodeType")
     .Description("Dummy type to enable Relay support with only default types. Do not use this type.")
     .Field("id")
     .Deprecated("Do not use this type.")
     .Resolver("__dummy")
     .Type <IdType>();
     descriptor.AsNode()
     .NodeResolver <string>((ctx, id) => Task.FromResult(new object()));
 }
コード例 #12
0
ファイル: GameNodeQueries.cs プロジェクト: Krashner/snowflake
        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));
        }
コード例 #13
0
        protected override void Configure(IObjectTypeDescriptor <SchemaPublishReport> descriptor)
        {
            descriptor.AsNode()
            .IdField(t => t.Id)
            .NodeResolver((ctx, id) =>
                          ctx.DataLoader <SchemaPublishReportByIdDataLoader>().LoadAsync(
                              id, ctx.RequestAborted));

            descriptor.Ignore(t => t.SchemaVersionId);
            descriptor.Ignore(t => t.EnvironmentId);
        }
コード例 #14
0
ファイル: PlayerType.cs プロジェクト: robhop/foosboy
        protected override void Configure(IObjectTypeDescriptor <Player> descriptor)
        {
            descriptor.AsNode()
            .IdField(t => t.Id)
            .NodeResolver((ctx, id) => ctx.Service <PlayerRepository>().GetPlayerByIdAsync(id));

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

            descriptor.Field(t => t.Avatar)
            .Type <NonNullType <StringType> >();
        }
コード例 #15
0
        protected override void Configure(IObjectTypeDescriptor <Team> descriptor)
        {
            descriptor.AsNode()
            .IdField(t => t.Id)
            .NodeResolver((ctx, id) => ctx.Service <PlayerRepository>().GetTeamByIdAsync(id));

            descriptor.Field(t => t.PlayerA)
            .Type <NonNullType <PlayerType> >();

            descriptor.Field(t => t.PlayerB)
            .Type <NonNullType <PlayerType> >();
        }
コード例 #16
0
        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));
        }
コード例 #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)));
        }
コード例 #18
0
        protected override void Configure(IObjectTypeDescriptor <ArticleDto> descriptor)
        {
            descriptor
            .AsNode()
            .IdField(a => a.Id)
            .NodeResolver(async(ctx, id) =>
            {
                // Attempt same way as in ArticleQueryTypeExtensions, fails
                var articleType = ctx.Schema.Types.Single(t => t.Name.Value == "Article");
                var fields      = ctx.CollectFields(articleType as ObjectType);

                // Attempt way I'd ideally want to work
                // (so I can do this from a base class that can resolve its sub types in one way)
                fields = ctx.CollectFields(this);

                return(await Task.FromResult(new ArticleDto(id, fields)));
            });
        }
コード例 #19
0
        protected override void Configure(
            IObjectTypeDescriptor <Customer> descriptor)
        {
            descriptor
            .AsNode()
            .IdField(t => t.Id)
            .NodeResolver((ctx, id) =>
            {
                return(Task.FromResult(
                           ctx.Service <CustomerRepository>()
                           .Customers.FirstOrDefault(t => t.Id.Equals(id))));
            });

            descriptor.Field(t => t.Name).Type <NonNullType <StringType> >();
            descriptor.Field(t => t.Street).Type <NonNullType <StringType> >();
            descriptor.Field(t => t.ConsultantId).Ignore();

            descriptor.Field <CustomerResolver>(
                t => t.GetConsultant(default, default))
コード例 #20
0
        protected override void Configure(
            IObjectTypeDescriptor <Consultant> descriptor)
        {
            descriptor
            .AsNode()
            .IdField(t => t.Id)
            .NodeResolver((ctx, id) =>
            {
                return(Task.FromResult(
                           ctx.Service <CustomerRepository>()
                           .Consultants.FirstOrDefault(t => t.Id.Equals(id))));
            });

            descriptor.Field(t => t.Name).Type <NonNullType <StringType> >();
            descriptor.Field("customers")
            .UsePaging <CustomerType>()
            .Resolve(ctx =>
            {
                Consultant consultant = ctx.Parent <Consultant>();
                return(ctx.Service <CustomerRepository>().Customers
                       .Where(t => t.ConsultantId == consultant.Id));
            });
        }
コード例 #21
0
 protected override void Configure(IObjectTypeDescriptor <Match> descriptor)
 {
     descriptor.AsNode()
     .IdField(t => t.Id)
     .NodeResolver((ctx, id) => ctx.Service <MatchRepository>().GetMatchByIdAsync(id));
 }