"Add or extend GraphQL-lite query support (CoreEx.Data.GraphQL) on a CoreEx *.Api host. USE FOR: first-time AddCoreExGraphQLLite/MapCoreExGraphQLLite wiring in Program.cs, registering AddQuery/AddGet roots over an entity's existing QueryArgsConfig, bulk-exposing reference data via AddReferenceDataQueries, adding a matching GraphQL root for an endpoint coreex-api just scaffolded, recording GraphQL enablement in the host's AGENTS.md. DO NOT USE FOR: REST controller endpoints (use coreex-api), defining or changing a QueryArgsConfig itself (use coreex-repository or coreex-refdata), general Program.cs setup unrelated to GraphQL (use coreex-scaffold)."
Resources
1Install
npx skillscat add avanade/coreex/coreex-graphql Install via the SkillsCat registry.
CoreEx: GraphQL-Lite Query Bridge
Guides you through adding CoreEx.Data.GraphQL (GraphQL-lite) to an *.Api host — wiring Program.cs, registering query/get roots over entities' existing QueryArgsConfig, optionally bulk-exposing reference data, and recording the enablement in that host's AGENTS.md.
When to Use
- First time a host needs a GraphQL query surface — only when explicitly asked, never proactively
- Adding a new
AddQuery/AddGetroot for an entity that already has aQueryArgsConfig+QueryAsync/GetAsyncon its read service - Bulk-exposing reference data types as GraphQL roots via
AddReferenceDataQueries coreex-apijust scaffolded a query endpoint on a host that already has GraphQL enabled, and the user wants a matching root added
When Not to Use
- REST controller/endpoint work — use
coreex-api - Defining or changing a
QueryArgsConfigitself — usecoreex-repository(entity queries) orcoreex-refdata(reference data queries). GraphQL-lite only bridges to the existing config; it never adds new filter/sort capability of its own - General host
Program.cssetup unrelated to GraphQL — usecoreex-scaffold - Subscribe/Relay hosts — GraphQL-lite is a REST-adjacent query surface for
*.Apihosts only
Quick Reference
Clarifying questions before writing any code:
0. Check the target host's AGENTS.md "This Host's Feature Configuration" section for an existing **GraphQL:** line — if already enabled, skip Program.cs wiring and go straight to root registration.
- Which
*.Apihost? - First-time enablement, or adding a root to an already-enabled host?
- Which entities/read services get a root? (each must already have a
QueryArgsConfig+QueryAsync/GetAsync) - Also bulk-expose reference data via
AddReferenceDataQueries? (default: Yes) - Enable introspection (
GraphQLLiteOptions.EnableIntrospection)? (default: No — secure-by-default) - Require authorization on the endpoint (
configure: rb => rb.RequireAuthorization())? (default: match the host's other endpoints — anonymous otherwise)
Key rules at a glance:
- Additive and opt-in — never add without an explicit ask
- Register via
builder.Services.AddCoreExGraphQLLite((o, sp) => o.AddQuery<T>(...).AddGet<T>(...)); map viaapp.MapCoreExGraphQLLite("/query")afterapp.MapControllers() - Never bypass a
QueryArgsConfigto add GraphQL-only filter/sort capability — extend the entity's existing config instead, so REST and GraphQL stay in exact lockstep - Resolve scoped services per-invocation via
CoreEx.ExecutionContext.GetRequiredService<T>()—IGraphQLEngineis a singleton; never capture a scoped instance from the rootIServiceProviderat registration time AddReferenceDataQueries(sp, ReferenceDataQueryArgsConfig.Default)bulk-registers every ref-data type known toReferenceDataOrchestrator, keyedref_<name>(alternate name where registered, elseType.Name); passexcludeTypesto opt specific types out- Add
.WithCoreExGraphQLTelemetry()alongside the host's other OpenTelemetry tracing extensions EnableIntrospectiondefaults tofalse;MapCoreExGraphQLLiteis anonymous by default — passRequireAuthorization()explicitly if the host's REST endpoints are secured- Record enablement in the host's
AGENTS.md"This Host's Feature Configuration" section as a plain**GraphQL:** Enabled (roots: ...)line — nodotnet newtemplate symbol; this is a per-host hand-authored fact added as a side effect of this skill - Use
args.GetIdentifier<TId>(name = "id")inside anAddGet<T>resolver to validate the identifier argument's presence, converting it toTIdviaTId.Parsewhere the boxed argument value isn't already an exact match (e.g. a variable-suppliedIntarrives boxed aslong, notint) — it throws anArgumentException(mapped toARGUMENT_ERROR) if missing/empty/not convertible toTId. Do not reach forargs.TryGetValue(...)directly —GraphQLLiteArgsis not a dictionary; useargs.Arguments.TryGetValue(...)only for non-identifier arguments. - The
TItem/TIdgenerics inAddQuery<TItem>/AddGet<TItem>are just whatever the entity's existing read-service method already returns (e.g.ProductLite, or the plain contract if there's no separate "Lite" projection) — there is no required naming convention; "Lite" in the samples is that domain's own projection name, not a CoreEx requirement. CoreEx.Data.GraphQLis preview-versioned, but the code samples in this skill (AddQuery,AddGet,AddReferenceDataQueries,GetIdentifier,MapCoreExGraphQLLite,AddCoreExGraphQLLite,WithCoreExGraphQLTelemetry) are verified against the real source and kept current — copy them as-is and just build. Do not pre-emptively reflect on the installed.dll"to be safe" before even attempting a build; that's wasted work when the sample already matches. Only fall back to inspecting the installed package (per the resolution order in `coreex-conventions.instructions.md#when-unsure-of-a-coreex-api-member`) if an actual compile error appears after copying the sample.
For full workflow and code examples see `references/workflow.md`.
Key References
- `/.github/instructions/coreex-host-setup.instructions.md` —
Program.cscomposition, GraphQL registration pattern - `/.github/instructions/coreex-api-controllers.instructions.md` —
QueryArgsConfig/QueryAsyncconventions that GraphQL-lite bridges to - Related skills: `coreex-api` (REST alternative/companion — hand off here after adding a REST query endpoint), `coreex-repository` and `coreex-refdata` (own the
QueryArgsConfigthat GraphQL-lite bridges to), `coreex-scaffold` (host setup) - `CoreEx.Data.GraphQL` AGENTS.md (CoreEx sample — illustrative, not in your project) — full registration API, query syntax, and non-goals
- Products sample `Program.cs` (CoreEx sample — illustrative) — working
AddCoreExGraphQLLite/MapCoreExGraphQLLiteexample