private void ConfigureTypeCar(IObjectTypeDescriptor descriptor) { descriptor .Field("cars") .Type <ListType <CarType> >() .Resolver(context => { QLContext qlContext = context.Service <QLContext>(); return(qlContext.Car.ToList()); }); descriptor .Field("car_add") .Type <CarType>() .Argument("input", x => { x.Type <CarInput>(); }) .Resolver(context => { Car car = context.Argument <Car>("input"); QLContext qlContext = context.Service <QLContext>(); IDbContextTransaction transaction = qlContext.Database.BeginTransaction(); try { qlContext.Car.Add(car); qlContext.SaveChanges(); transaction.Commit(); } catch (System.Exception) { transaction.Rollback(); } finally { transaction.Dispose(); } return(car); }); descriptor .Field("car_edit") .Type <CarType>() .Argument("input", x => { x.Type <CarInput>(); }) .Resolver(context => { Car car = context.Argument <Car>("input"); QLContext qlContext = context.Service <QLContext>(); IDbContextTransaction transaction = qlContext.Database.BeginTransaction(); try { qlContext.Car.Update(car); qlContext.SaveChanges(); transaction.Commit(); } catch (System.Exception) { transaction.Rollback(); } finally { transaction.Dispose(); } return(car); }); descriptor .Field("car_find") .Type <CarType>() .Argument("id", x => { x.Type <IntType>(); x.DefaultValue(0); }) .Resolver(context => { int id = context.Argument <int>("id"); QLContext qlContext = context.Service <QLContext>(); return(qlContext.Car.Find(id)); }); descriptor .Field("car_remove") .Type <RemoveType>() .Argument("id", x => { x.Type <IntType>(); x.DefaultValue(0); }) .Resolver(context => { int count = 0; int id = context.Argument <int>("id"); QLContext qlContext = context.Service <QLContext>(); var car = qlContext.Car.Find(id); if (car != null) { IDbContextTransaction transaction = qlContext.Database.BeginTransaction(); try { qlContext.Car.Remove(car); count = qlContext.SaveChanges(); transaction.Commit(); } catch { transaction.Rollback(); } finally { transaction.Dispose(); } } return(Remove.Create(count)); }); }
/// <inheritdoc/> protected override void Configure(IObjectTypeDescriptor <VersionGameIndex> descriptor) { descriptor.Field(x => x.GameIndex) .Description("The internal id of an API resource within game data."); descriptor.UseNamedApiResourceField <VersionGameIndex, Version, VersionType>(x => x.Version); }
protected override void Configure(IObjectTypeDescriptor descriptor) { descriptor.Name(UserGraphType.GraphName); descriptor.Field <UserGqlOut>(t => t.ForAdminEyesOnly); }
protected override void Configure( IObjectTypeDescriptor <Query> descriptor) { descriptor.Field(t => t.Foos).UseFiltering <Foo>(); }
protected override void Configure(IObjectTypeDescriptor <Product> descriptor) { base.Configure(descriptor); descriptor .ImplementsNode() .IdField(c => c.Id) .ResolveNode((ctx, id) => ctx.DataLoader <ProductsByIdBatchDataLoader>().LoadAsync(id, ctx.RequestAborted)); descriptor .Field(c => c.Name) .Name("name") .Type <NonNullType <StringType> >(); descriptor .Field(c => c.Reference) .Name("reference") .Type <NonNullType <StringType> >(); descriptor .Field(c => c.CreatedOn) .Name("createdOn"); descriptor .Field(c => c.UpdatedOn) .Name("updatedOn"); descriptor .Field(c => c.Vat) .Name("vat"); descriptor .Field(c => c.Available) .Name("available"); descriptor .Field(c => c.RatingsCount) .Name("ratingsCount"); descriptor .Field(c => c.PicturesCount) .Name("picturesCount"); descriptor .Field(c => c.CatalogsPricesCount) .Name("catalogsCount") .Authorize(Policies.PRODUCER); descriptor .Field(c => c.QuantityPerUnit) .Name("quantityPerUnit"); descriptor .Field(c => c.Unit) .Name("unit"); descriptor .Field(c => c.Conditioning) .Name("conditioning"); descriptor .Field(c => c.Description) .Name("description"); descriptor .Field(c => c.Weight) .Name("weight"); descriptor .Field(c => c.Rating) .Name("rating"); descriptor .Field(c => c.Picture) .Resolve(c => PictureExtensions.GetPictureUrl(c.Parent <Product>().Id, c.Parent <Product>().Picture, PictureSize.MEDIUM)) .Name("picture"); descriptor .Field("imageLarge") .Resolve(c => PictureExtensions.GetPictureUrl(c.Parent <Product>().Id, c.Parent <Product>().Picture, PictureSize.LARGE)) .Type <StringType>(); descriptor .Field("imageMedium") .Resolve(c => PictureExtensions.GetPictureUrl(c.Parent <Product>().Id, c.Parent <Product>().Picture, PictureSize.MEDIUM)) .Type <StringType>(); descriptor .Field("imageSmall") .Resolve(c => PictureExtensions.GetPictureUrl(c.Parent <Product>().Id, c.Parent <Product>().Picture, PictureSize.SMALL)) .Type <StringType>(); descriptor .Field("isReturnable") .Resolve(c => c.Parent <Product>().ReturnableId.HasValue) .Type <BooleanType>(); descriptor .Field("visibleTo") .Resolve(c => c.Parent <Product>().VisibleTo) .Authorize(Policies.PRODUCER); descriptor .Field("vatPricePerUnit") .UseDbContext <QueryDbContext>() .ResolveWith <ProductResolvers>(c => c.GetProductVatPricePerUnit(default, default, default, default, default, default))
protected override void Configure(IObjectTypeDescriptor <AnswersAssessmentQuestionDto> descriptor) { descriptor.Field(e => e.Id); descriptor.Field(e => e.QuestionText).Type <NonNullType <StringType> >(); descriptor.Field(e => e.Questions).Type <NonNullType <ListType <NonNullType <UuidType> > > >(); }
protected override void Configure(IObjectTypeDescriptor <PersistedGrant> descriptor) { descriptor.Field(x => x.Key) .Type <NonNullType <IdType> >(); }
protected override void Configure(IObjectTypeDescriptor <Recipe> descriptor) { base.Configure(descriptor); descriptor.Field(r => r.Id) .Type <NonNullType <IdType> >(); // Ignored descriptor.Field(r => r.UserId) .Ignore(); descriptor.Field(r => r.User) .Ignore(); descriptor.Field(r => r.RecipeTags) .Ignore(); // Properties descriptor.Field(r => r.Title) .Type <NonNullType <StringType> >(); descriptor.Field(r => r.Image) .Type <NonNullType <StringType> >(); descriptor.Field(r => r.PrepTime) .Type <NonNullType <IntType> >(); descriptor.Field(r => r.Kcal) .Type <NonNullType <IntType> >(); descriptor.Field(r => r.Protein) .Type <NonNullType <IntType> >(); descriptor.Field(r => r.Carbs) .Type <NonNullType <IntType> >(); descriptor.Field(r => r.Fat) .Type <NonNullType <IntType> >(); // Resolvers descriptor .Field("tags") .Type <NonNullType <ListType <TagType> > >() .Resolver(ctx => { var repository = ctx.Service <ITagRepository>(); IDataLoader <Guid, Tag[]> recipeDataLoader = ctx.GroupDataLoader <Guid, Tag>( "tagsByRecipeId", repository.GetTagsByRecipeId); return(recipeDataLoader.LoadAsync(ctx.Parent <Recipe>().Id)); }); }
protected override void Configure(IObjectTypeDescriptor <UserSignInPayload> descriptor) { descriptor.Field(x => x.Id); descriptor.Field(x => x.Nickname); descriptor.Field(x => x.Token); }
protected override void Configure(IObjectTypeDescriptor <PositionApiModel> descriptor) { descriptor.Field(f => f.Id).Type <NonNullType <IntType> >(); descriptor.Field(f => f.Name).Type <NonNullType <StringType> >(); descriptor.Field(f => f.Openings).Type <NonNullType <IntType> >(); }
protected override void Configure(IObjectTypeDescriptor <Dog> descriptor) { descriptor.Field(t => t.WithTail).Type <NonNullType <BooleanType> >(); descriptor.Field(t => t.GetNames()).Type <ListType <StringType> >(); }
protected override void Configure(IObjectTypeDescriptor <GradedDancerDish> descriptor) { descriptor .Field(t => t.Dancer) .ResolveWith <GradedDancerDishResolvers>(t => t.GetDancerAsync(default !, default !, default));
protected override void Configure(IObjectTypeDescriptor <T> descriptor) { var wrappedType = typeof(T); descriptor.Name(wrappedType.Name); const BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly; var members = Enumerable.Union( wrappedType.GetFields(bindingFlags).Cast <MemberInfo>(), wrappedType.GetProperties(bindingFlags).Cast <MemberInfo>() ); foreach (var member in members) { var memberType = member.GetMemberType(); var fieldDescriptor = descriptor.Field(member.Name); if (SchemaOrgHelpers.IsUnionType(memberType)) { var unionTypes = SchemaOrgHelpers.GetUnionMemberTypes(memberType) .Select( t => { var newTypeCtor = typeof(ObjectType <>) .MakeGenericType(t) .GetConstructor(Array.Empty <Type>()); if (newTypeCtor is null) { throw new Exception(); } var objectType = newTypeCtor.Invoke(null) as ObjectType; return(objectType); } ); var graphQLUnionType = new UnionType( desc => { desc.Name(member.Name); foreach (var unionType in unionTypes) { desc.Type(unionType); } } ); fieldDescriptor.Type(graphQLUnionType); } else if (memberType.IsEnum) { var newTypeCtor = typeof(EnumType <>) .MakeGenericType(memberType) .GetConstructor(Array.Empty <Type>()); if (newTypeCtor is null) { throw new Exception(); } var objectType = newTypeCtor.Invoke(null) as EnumType; if (objectType is null) { throw new Exception(); } fieldDescriptor.Type(objectType); } else if ( GraphQLTypeHelpers.TryGetBuiltInScalarType( memberType, out var scalarType ) ) { fieldDescriptor.Type(scalarType); } else { // Is a normal type. } } }
protected override void Configure(IObjectTypeDescriptor <IdentityUser> descriptor) { descriptor.Field(t => t.AccessFailedCount); descriptor.Field(t => t.ConcurrencyStamp); descriptor.Field(t => t.Email); descriptor.Field(t => t.EmailConfirmed); descriptor.Field(t => t.Id); descriptor.Field(t => t.LockoutEnabled); descriptor.Field(t => t.LockoutEnd); descriptor.Field(t => t.NormalizedEmail); descriptor.Field(t => t.NormalizedUserName); descriptor.Field(t => t.PasswordHash).Ignore(); descriptor.Field(t => t.PhoneNumber); descriptor.Field(t => t.PhoneNumberConfirmed); descriptor.Field(t => t.SecurityStamp); descriptor.Field(t => t.TwoFactorEnabled); descriptor.Field(t => t.UserName); }
protected override void Configure(IObjectTypeDescriptor descriptor) { descriptor.Field("newState") .Argument("state", a => a.Type <StringType>()) .Resolver(c => DataStore.State = c.Argument <string>("state")); }
protected override void Configure(IObjectTypeDescriptor <Command> descriptor) { descriptor.Description("Represents commands that can be run on a platform"); descriptor .Field(c => c.Platform) .ResolveWith <Resolvers>(c => c.GetPlatform(default !, default !))
protected override void Configure(IObjectTypeDescriptor <Unit> descriptor) { descriptor.Name("Unit"); descriptor.Field(x => x.ToString()).Type <NonNullType <StringType> >().Name("Unit").Description("Unit"); descriptor.BindFieldsExplicitly(); }
protected override void Configure(IObjectTypeDescriptor descriptor) { descriptor.Field("test").Resolve("test"); }
protected override void Configure(IObjectTypeDescriptor <PickingProduct> descriptor) { base.Configure(descriptor); descriptor.Name("PickingProduct"); descriptor .ImplementsNode() .IdField(c => c.Id) .ResolveNode((ctx, id) => ctx.DataLoader <PickingProductsByIdBatchDataLoader>().LoadAsync(id, ctx.RequestAborted)); descriptor .Field(c => c.ProductId) .ID(nameof(Product)) .Name("productId"); descriptor .Field(c => c.Quantity) .Name("quantity"); descriptor .Field(c => c.Vat) .Name("vat"); descriptor .Field(c => c.TotalWeight) .Name("totalWeight"); descriptor .Field(c => c.UnitOnSalePrice) .Name("unitOnSalePrice"); descriptor .Field(c => c.UnitVatPrice) .Name("unitVatPrice"); descriptor .Field(c => c.UnitWholeSalePrice) .Name("unitWholeSalePrice"); descriptor .Field(c => c.UnitVatPrice) .Name("unitVatPrice"); descriptor .Field(c => c.UnitWeight) .Name("unitWeight"); descriptor .Field(c => c.TotalWholeSalePrice) .Name("totalWholeSalePrice"); descriptor .Field(c => c.TotalVatPrice) .Name("totalVatPrice"); descriptor .Field(c => c.TotalOnSalePrice) .Name("totalOnSalePrice"); descriptor .Field(c => c.TotalReturnableWholeSalePrice) .Name("totalReturnableWholeSalePrice"); descriptor .Field(c => c.TotalReturnableVatPrice) .Name("totalReturnableVatPrice"); descriptor .Field(c => c.TotalReturnableOnSalePrice) .Name("totalReturnableOnSalePrice"); descriptor .Field(c => c.TotalProductWholeSalePrice) .Name("totalProductWholeSalePrice"); descriptor .Field(c => c.TotalProductVatPrice) .Name("totalProductVatPrice"); descriptor .Field(c => c.TotalProductOnSalePrice) .Name("totalProductOnSalePrice"); descriptor .Field(c => c.HasReturnable) .Name("isReturnable"); descriptor .Field(c => c.QuantityPerUnit) .Name("quantityPerUnit"); descriptor .Field(c => c.Conditioning) .Name("conditioning"); descriptor .Field(c => c.Unit) .Name("unit"); descriptor .Field(c => c.ReturnableId) .ID(nameof(Returnable)) .Name("returnableId"); descriptor .Field(c => c.PurchaseOrderId) .ID(nameof(PurchaseOrder)) .Name("purchaseOrderId"); descriptor .Field("purchaseOrder") .ResolveWith <PickingProductResolvers>(c => c.GetPurchaseOrder(default, default, default))
protected override void Configure(IObjectTypeDescriptor <ClientSecret> descriptor) { descriptor.Field(x => x.Id) .Type <NonNullType <IdType> >(); }
protected override void Configure(IObjectTypeDescriptor <UserOutDto> descriptor) { descriptor.Field(x => x.Id).Description("ID of the user"); descriptor.Field(x => x.Email).Description("Email of the user"); descriptor.Field(x => x.Username).Description("Username of the user"); }
private static void RegisterPokemonResources(IObjectTypeDescriptor descriptor) { descriptor.Field("ability") .UseNamedApiResource <Ability, AbilityType>(); descriptor.Field("abilities") .UseNamedResourcePaging <Ability, AbilityType>(); descriptor.Field("characteristic") .UseApiResource <Characteristic, CharacteristicType>(); descriptor.Field("eggGroup") .UseNamedApiResource <EggGroup, EggGroupType>(); descriptor.Field("gender") .UseNamedApiResource <Gender, GenderType>(); descriptor.Field("type") .UseNamedApiResource <Type, TypePropertyType>(); descriptor.Field("types") .UseNamedResourcePaging <Type, TypePropertyType>(); descriptor.Field("pokemonSpecies") .UseNamedApiResource <PokemonSpecies, PokemonSpeciesType>(); descriptor.Field("pokemonSpeciesPage") .UseNamedResourcePaging <PokemonSpecies, PokemonSpeciesType>(); descriptor.Field("pokemon") .UseNamedApiResource <Pokemon, Resources.Pokemons.PokemonType>(); descriptor.Field("pokemons") .UseNamedResourcePaging <Pokemon, Resources.Pokemons.PokemonType>(); }
protected override void Configure( IObjectTypeDescriptor <Foo> descriptor) { descriptor.Field(t => t.Bar).Type <NonNullType <BarType> >(); }
private static void RegisterMachineResources(IObjectTypeDescriptor descriptor) { descriptor.Field("machine") .UseApiResource <Machine, MachineType>(); }
protected override void Configure(IObjectTypeDescriptor <Artist> descriptor) { descriptor.Field(t => t.MusicBrainzId) .Type <StringType>() .Name("mbid"); }
private static void RegisterEvolutionResources(IObjectTypeDescriptor descriptor) { descriptor.Field("evolutionChain") .UseApiResource <EvolutionChain, EvolutionChainType>(); }
protected override void Configure(IObjectTypeDescriptor <StreetAddressDto> descriptor) { descriptor.Field(t => t.CalculateSize()).Ignore(); descriptor.Field(t => t.Clone()).Ignore(); descriptor.Field(t => t.Equals(null)).Ignore(); }
protected override void Configure(IObjectTypeDescriptor <Command> descriptor) { descriptor.Description("Represents any executable command"); descriptor .Field(c => c.Platform) .ResolveWith <Resolvers>(c => c.GetPlatform(default !, default !))
protected override void Configure(IObjectTypeDescriptor <Query> descriptor) { descriptor.Name("Query"); descriptor.Field(t => t.TestProp).Name("test"); }
protected override void Configure(IObjectTypeDescriptor <Model.Page> descriptor) { descriptor.Description("Hours Attend"); descriptor.Field(p => p.Lang) .UseDbContext <DrMofradDbContext>() .ResolveWith <Resolver>(resolver => resolver.GetLang(default !, default !));