An ABP module that allows using application services by GraphQL. It also accepted custom schemes and types you defined.
-
Install the following NuGet packages. (see how)
- EasyAbp.Abp.GraphQL.Application
- EasyAbp.Abp.GraphQL.Application.Contracts
- EasyAbp.Abp.GraphQL.HttpApi
- EasyAbp.Abp.GraphQL.HttpApi.Client
- EasyAbp.Abp.GraphQL.Provider.GraphQLDotnet (install to the Application layer)
- EasyAbp.Abp.GraphQL.Web.Altair (optional)
- EasyAbp.Abp.GraphQL.Web.GraphiQL (optional)
- EasyAbp.Abp.GraphQL.Web.Playground (optional)
- EasyAbp.Abp.GraphQL.Web.Voyager (optional)
-
Add
DependsOn(typeof(Abp.GraphQLXxxModule))
attribute to configure the module dependencies. (see how)
-
Configure the module to auto lookup AppServices.
Configure<AbpGraphQLOptions>(options => { // Find entities: Book, Author, City... options.AppServiceSchemes.Configure( typeof(MyProjectApplicationContractsModule).Assembly); // Find entities: IdentityUser, IdentityRole options.AppServiceSchemes.Configure( typeof(AbpIdentityApplicationContractsModule).Assembly); });
-
Configure the GraphQL UIs (if you just installed them).
Configure<AbpAntiForgeryOptions>(options => { // PR need: inject the RequestVerificationToken header to UI's AJAX request. options.AutoValidateFilter = type => type.Namespace != null && !type.Namespace.StartsWith("EasyAbp.Abp.GraphQL"); }); Configure<AbpGraphiQLOptions>(options => { // options.UiBasicPath = "/myPath"; });
-
Now you can query your entities with GraphQL.
query { book(id: "CA2EBE5D-D0DC-4D63-A77A-46FF520AEC44") { name author { id name } } }
The following contents are for the graphql-dotnet provider, please go to graphql-dotnet's GitHub repo or docs site for more information.
You can replace the AppServiceQuery class for an entity you want to customize, see the demo.
- Create your schema.
public class MyCustomSchema : Schema, ITransientDependency { public MySchema(IServiceProvider serviceProvider) : base(serviceProvider) { Query = serviceProvider.GetRequiredService<MyCustomQuery>(); } }
- Configure to map the
/MyCustom
path to MyCustomSchema for UIs (if you want).Configure<AbpEndpointRouterOptions>(options => { options.EndpointConfigureActions.Add(builderContext => { var uiOptions = builderContext.ScopeServiceProvider.GetRequiredService<IOptions<AbpGraphiQLOptions>>().Value; var schemaUiOption = (GraphiQLOptions)uiOptions.Clone(); schemaUiOption.GraphQLEndPoint = schemaUiOption.GraphQLEndPoint.Value.EnsureEndsWith('/') + "MyCustom"; schemaUiOption.SubscriptionsEndPoint = schemaUiOption.SubscriptionsEndPoint.Value.EnsureEndsWith('/') + "MyCustom"; builderContext.Endpoints.MapGraphQLGraphiQL(schemaUiOption, uiOptions.UiBasicPath.RemovePreFix("/").EnsureEndsWith('/') + "MyCustom"); }); });
- Support Query.
- Support Mutation.
- Support Subscription.
- Improve UI modules.