Add @enonic-types/lib-graphql types package #200 - #201
Open
rymsha wants to merge 1 commit into
Open
Conversation
Adds a published TypeScript types package for lib-graphql so consumers (starting with app-guillotine) no longer have to hand-maintain declarations for `/lib/graphql`, `/lib/graphql-connection` and `/lib/graphql-rx`. Type model - `GraphQLType` and per-kind subtypes (`GraphQLObjectType`, `GraphQLInputObjectType`, `GraphQLInterfaceType`, `GraphQLUnionType`, `GraphQLEnumType`, `GraphQLScalarType`, `GraphQLTypeReference`) are opaque, nominally-branded handles. Consumers pass them around but do not introspect them. `GraphQLObjectType` exposes `getName()` because `createConnectionType` uses it to derive edge / connection names. - Fields on object / interface types are typed with `GraphQLFieldConfig<Source, Context>`; the resolver's `env.args` is `any` in the default signature so callers can narrow to a concrete `Args` interface by annotating the resolver's `env` parameter, without an explicit cast. Runtime never validates arg shape (the schema does), so this matches actual behavior. - `DataFetchingEnvironment<Source, Args, Context>` — three generics, all defaulted to `unknown` / `Record<string, unknown>`, reflecting what the Java bridge actually guarantees. Contents - `types/index.d.ts` — three `declare module` blocks: `/lib/graphql`, `/lib/graphql-connection`, `/lib/graphql-rx`. - `types/package.json` — `@enonic-types/lib-graphql` manifest, `@enonic-types/core` peer dependency, `publishConfig.access: public`, version `0.0.0` (substituted at build). - `types/tsconfig.json` + `types/test/typecheck.ts` — build-only smoke test that exercises a realistic schema (object type with a typed resolver reading source, args and context, an enum + input + interface + union, a Relay-style connection built through graphql-connection, and a graphql-rx publish processor / subscriber). Runs under `tsc --noEmit` with strict mode. - `build.gradle` — `assembleTypes` Copy task -> `build/types/` (version substituted from `project.version`, tsconfig + test excluded); `jar.dependsOn assembleTypes`. - `.github/workflows/enonic-gradle.yml` — `npmPublish: true` on build-and-publish + top-level `id-token: write` / `contents: write` permissions for OIDC trusted publishing. Closes #200 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #201 +/- ##
=========================================
Coverage 87.26% 87.26%
Complexity 93 93
=========================================
Files 13 13
Lines 369 369
Branches 50 50
=========================================
Hits 322 322
Misses 23 23
Partials 24 24 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds a publishable TypeScript declaration package (@enonic-types/lib-graphql) to provide first-party typings for Enonic XP’s /lib/graphql, /lib/graphql-connection, and /lib/graphql-rx, and wires CI/build to assemble and publish it.
Changes:
- Adds ambient module declarations (
types/index.d.ts) covering schema building, connection helpers, and reactive helpers. - Adds a strict
tsc --noEmitsmoke test (types/test/typecheck.ts) plus a localtypes/tsconfig.jsonfor typechecking. - Adds Gradle/CI automation to assemble the
types/package intobuild/types/and enable npm trusted publishing.
Reviewed changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
types/index.d.ts |
Declares the public TS API surface for /lib/graphql* modules (schema builder, connection helper, rx helper). |
types/package.json |
Defines the npm package metadata for @enonic-types/lib-graphql. |
types/tsconfig.json |
Typecheck configuration for the declaration package + compile-only test. |
types/test/typecheck.ts |
Compile-only smoke test exercising the declared typings with a realistic schema. |
build.gradle |
Adds assembleTypes task to stage the npm package under build/types/ with version substitution. |
.github/workflows/enonic-gradle.yml |
Enables OIDC permissions and npmPublish: true in the build-and-publish workflow. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+8
to
+10
| "esModuleInterop": true, | ||
| "skipLibCheck": true, | ||
| "baseUrl": ".", |
Comment on lines
+29
to
+31
| "dependencies": { | ||
| "@enonic-types/core": "^8.0.0" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a published TypeScript types package
@enonic-types/lib-graphqlso consumers no longer hand-maintain declarations for/lib/graphql,/lib/graphql-connectionand/lib/graphql-rx. Mirrors the lib-mustache #66 scaffolding; the type authoring is the real work here.Type model
GraphQLTypeand per-kind subtypes (GraphQLObjectType,GraphQLInputObjectType,GraphQLInterfaceType,GraphQLUnionType,GraphQLEnumType,GraphQLScalarType,GraphQLTypeReference) are opaque, nominally-branded handles. Consumers pass them around but do not introspect them.GraphQLObjectTypeexposesgetName()becausecreateConnectionTypeuses it to derive edge / connection names.GraphQLFieldConfig<Source, Context>. The resolver'senv.argsisanyin the default signature so callers can narrow to a concreteArgsinterface by annotating the resolver'senvparameter, without an explicit cast:anyhere matches actual behavior — it's a bivariance escape hatch, not blanket looseness.DataFetchingEnvironment<Source, Args, Context>— three generics, all defaulted tounknown/Record<string, unknown>, reflecting what the Java bridge actually guarantees.Date,DateTime,Time,Json,LocalDateTime,LocalTime) are typed asGraphQLScalarType— same shape as the base graphql-java scalars.Every signature was cross-checked against
GraphQlBean.java,DataFetchingEnvironmentMapper.java,RxBean.java(param order, return types), and thegraphql.js/graphql-connection.js/graphql-rx.jswrappers.Contents
types/index.d.ts— threedeclare moduleblocks:/lib/graphql,/lib/graphql-connection,/lib/graphql-rx.types/package.json—@enonic-types/lib-graphqlmanifest,@enonic-types/corepeer dependency,publishConfig.access: public, version0.0.0(substituted at build).types/tsconfig.json+types/test/typecheck.ts— build-only smoke test that exercises a realistic schema (object type with a typed resolver reading source, args and context, an enum + input + interface + union, a Relay-style connection built through graphql-connection, and a graphql-rx publish processor / subscriber). Runs undertsc --noEmitwith strict mode.build.gradle—assembleTypesCopy task ->build/types/(version substituted fromproject.version, tsconfig + test excluded from the published artifact);jar.dependsOn assembleTypes..github/workflows/enonic-gradle.yml—npmPublish: trueon build-and-publish + top-levelid-token: write/contents: writepermissions for OIDC trusted publishing.Verified locally
./gradlew buildgreen.build/types/containsindex.d.ts+ apackage.jsonwithversionsubstituted to the project version (3.1.0-SNAPSHOT).tsc --noEmit -p types/tsconfig.jsonpasses against the realistic-schema smoke test.Follow-up
app-guillotineis the primary consumer — once this publishes, guillotine (and any other apps currently building against untyped/lib/graphql*) can depend on@enonic-types/lib-graphqlinstead of local declarations.@enonic-types/lib-graphqlname (release-tools Bump graphql-java-extended-scalars from 1.0 to 16.0.0 #71 merged).Closes #200
🤖 Generated with Claude Code