Git Product home page Git Product logo

abp.graphql's Introduction

Abp.GraphQL

ABP version NuGet NuGet Download Discord online GitHub stars

An ABP module that allows using application services by GraphQL. It also accepted custom schemes and types you defined.

UI

Installation

  1. 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)
  2. Add DependsOn(typeof(Abp.GraphQLXxxModule)) attribute to configure the module dependencies. (see how)

Usage

  1. 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);
    });
  2. 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";
    });
  3. Now you can query your entities with GraphQL.

    query {
       book(id: "CA2EBE5D-D0DC-4D63-A77A-46FF520AEC44") {
          name
          author {
             id
             name
          }
       }
    }

Q&A

The following contents are for the graphql-dotnet provider, please go to graphql-dotnet's GitHub repo or docs site for more information.

How to customize an auto-created AppService scheme?

You can replace the AppServiceQuery class for an entity you want to customize, see the demo.

How to create a schema myself?

  1. Create your schema.
    public class MyCustomSchema : Schema, ITransientDependency
    {
        public MySchema(IServiceProvider serviceProvider) : base(serviceProvider)
        {
            Query = serviceProvider.GetRequiredService<MyCustomQuery>();
        }
    }
  2. 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");
        });
    });

Road map

  • Support Query.
  • Support Mutation.
  • Support Subscription.
  • Improve UI modules.

abp.graphql's People

Contributors

gdlcf88 avatar vcup avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.