ข้ามไปยังเนื้อหา

Tutorial: GraphQL API

เนื้อหานี้ยังไม่ได้แปลเป็นภาษาไทย แสดงเป็นภาษาอังกฤษแทน

Cephalon.AspNetCore.GraphQL is the GraphQL transport adapter. Each module contributes a subschema; the host federates them into a single endpoint. This tutorial walks through standing up a federated schema, wiring auth, and writing module-owned resolvers.

  • a Products module that contributes type Product and query products.
  • an Orders module that contributes type Order and query orders.
  • federation that lets clients query both in one request.
  • field-level authorisation gated by Cephalon identity capabilities.
public sealed class ProductsGraphQlModule : GraphQlBehaviorModuleBase
{
public override ModuleDescriptor Describe() => new("Acme.Store.GraphQL.Products", "1.0.0", [Capability.Data]);
protected override void ConfigureGraphQl(IGraphQlBehaviorBuilder builder)
{
builder.AddType<ProductType>();
builder.AddQueryField("products", resolve: async (catalog, ct) => await catalog.ListAsync(ct));
}
}

Full walkthrough lands in the next docs push. Until then, see: