Skip to content

Commit d548df1

Browse files
authored
Merge pull request #943 from graphql-java-kickstart/agent-friendly-p1-agent-rules
Commit the agent rules and the verify-tools skill
2 parents eeddfc0 + a3c3861 commit d548df1

173 files changed

Lines changed: 3702 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
name: verify-tools
3+
description: Prove a graphql-java-tools behavior the way a consuming app sees it. Installs this checkout into a private Maven repo, builds a schema from SDL files and resolver classes in a separate probe project through the public API, runs GraphQL operations, and saves the printed schema, JSON results and library warnings as evidence. Use to confirm a fix or feature works from the outside (not just in the library's own unit tests), or to reproduce an issue report. Run it before pushing any schema-building change to an open PR, including refactors and new or changed library warnings, whose only proof is the probe's log.
4+
---
5+
6+
# Verify graphql-java-tools from a consumer
7+
8+
`probe/` is a separate Maven project that depends on the jar installed from a checkout, so it sees only the public API,
9+
unlike `src/test`. `mvn verify` still runs for every change. This skill proves one behavior end to end in minutes, and is
10+
where bugfixes and small features stop.
11+
12+
## Run
13+
14+
`probe.sh` sits next to this file and verifies the checkout of the current directory. Every clone and worktree has its
15+
own copy, so run it from the checkout root. To verify a commit that predates this skill, check it out in its own worktree
16+
and run another checkout's `probe.sh` from inside it.
17+
18+
```bash
19+
.claude/skills/verify-tools/probe.sh doctor # checkout, branch, install state, lock
20+
.claude/skills/verify-tools/probe.sh list # scenario names
21+
.claude/skills/verify-tools/probe.sh install # clean-build the checkout into the private repo
22+
.claude/skills/verify-tools/probe.sh run <scenario> [--graphql-java <ver>] # build the schema, run every operation
23+
.claude/skills/verify-tools/probe.sh clean # remove this checkout's work dir, keep evidence
24+
```
25+
26+
- `run` first installs the checkout into a private Maven repo under `$TMPDIR/verify-tools/work/<checkout>-<path hash>/` when
27+
the install is missing or stale, meaning HEAD or uncommitted `pom.xml`/`src/` changes differ from the last install. It
28+
reads `~/.m2` but never writes it. The install runs `mvn clean install`, so it empties the checkout's `target/`. Don't
29+
run it while another build uses the same checkout. The work dir is keyed on the checkout's path, so clones and worktrees
30+
run in parallel, even when two share a folder name. If `doctor` shows the lock held by a live pid, wait for that run.
31+
- It builds the schema from the scenario's `parser()`, prints it, then executes every `*.graphql` in
32+
`probe/src/main/resources/scenarios/<name>/` in name order, with `<op>.variables.json` as variables. It collects
33+
subscription events until the stream completes, for at most 10 seconds.
34+
- Exit `0`: the schema built and every operation ran, though operations can still return GraphQL errors. `2`: the build
35+
threw. `1`: harness failure (install log or `maven.log`) or a held lock. `64`: bad usage, such as a missing or unknown
36+
scenario.
37+
- `--graphql-java` swaps only the runtime graphql-java, like a user who pins another version. It doesn't recompile the
38+
library against it. `--skip-install` runs a stale install on purpose and doesn't count as proof.
39+
40+
## Evidence
41+
42+
`run` prints its evidence directory, `$TMPDIR/verify-tools/evidence/<timestamp>-<scenario>[-gj<version>][-<n>]/`, on its last
43+
line.
44+
45+
| File | Holds |
46+
|---|---|
47+
| `summary.txt` | Jars actually loaded, Java version, unused definitions, build result, errors per operation |
48+
| `run.txt` | Checkout, commit, source fingerprint and install stamp, command, exit code |
49+
| `schema.graphqls` | The executable schema as graphql-java prints it, generated types included |
50+
| `<op>.json` | The spec-shaped result, `events` for a subscription, or `threw` when `execute` threw |
51+
| `probe.log` | WARN and above, plus INFO from `graphql.kickstart.tools`, where the library's build warnings land |
52+
| `inspect.txt` | What the scenario's `inspect(schema)` returned |
53+
| `build-error.txt` | Stack trace when the build threw |
54+
55+
Proof standards:
56+
57+
- `summary.txt`'s `graphql-java-tools jar` is inside the work dir, and `run.txt`'s fingerprint equals its install stamp.
58+
Otherwise you tested another build.
59+
- Quote the operation and the relevant part of `<op>.json`. Cite `schema.graphqls` for schema shape, `probe.log` for
60+
warnings, and `build-error.txt` with exit `2` for build failures.
61+
- For a regression, a new warning or a clearer error, run the same scenario on the fix and on `master` (or the commit
62+
before the fix), in two worktrees, and show both. They differ in exactly the way the issue describes.
63+
- Report a sub-feature you didn't run as skipped, with the reason. Another scenario doesn't cover it.
64+
- An expected value in `features/` that stops matching is a finding to report, not something to edit away.
65+
66+
## Adding a scenario
67+
68+
1. Write the SDL as `probe/src/main/resources/scenarios/<name>/schema.graphqls` and load it with `.file(...)`, unless the
69+
behavior is about `schemaString`.
70+
2. Add `object <Name> : Scenario` with `name` and `parser()` in `probe/src/main/kotlin/scenarios/<Name>.kt`. Being an
71+
object in that package registers it. Classes share the package, so prefix resolver and data classes with the scenario.
72+
Use only public API. If the probe needs `internal` or test classes, a user can't reach the behavior either, so report
73+
that.
74+
3. Add operations as `NN-<what>.graphql`, plus `NN-<what>.variables.json` when they take variables. graphql-java rejects
75+
a second `__type` in one operation and still exits `0`, so read several types through `__schema { types { ... } }`.
76+
4. Override what the scenario needs. `operations` reuses another scenario's operation directory. `schema(parser)` takes
77+
another build path such as `toReadOnlySchema()`. `inspect(schema)` returns evidence the printer doesn't show, and
78+
`probe.dumpDirectives(schema)` lists every element's applied and legacy directives. `graphQL(builder)` and
79+
`input(builder)` add instrumentation, context or data loaders.
80+
5. A scenario that doesn't compile breaks every checkout's run, so finish it before running. Keep a scenario that proves
81+
a lasting feature and add its exact expected results to the matching file in `features/`. Delete a one-off
82+
reproduction after reporting.
83+
84+
`features/README.md` maps each feature to its scenarios and expected results. Delete evidence directories by hand once
85+
reported.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# graphql-java-tools verification map
2+
3+
Each file below is one user-visible feature, with the scenarios that prove it and their exact expected results. The
4+
commands and proof standards are in `../SKILL.md`. Scenario data is fixed, so expected values are literal.
5+
6+
A feature file has an H1 title and one paragraph on the behavior a user sees, then three H2 sections: `Sub-features` (short
7+
IDs, one line each), `Expected results` (each scenario's `run` command and what its evidence shows), and `Gotchas` (traps
8+
that waste or invalidate a run, and how the result looked before the fix).
9+
10+
## Features
11+
12+
- [Schema building](./schema-building.md): SDL files, root and nested resolvers, property and getter discovery, custom
13+
scalars, the unused-type warning, the missing-resolver error and the read-only schema (`bookstore`,
14+
`bookstore-missing-resolver`, `read-only-schema`).
15+
- [Arguments and input types](./arguments-and-inputs.md): SDL defaults, enums, lists, input objects mapped to classes,
16+
omitted versus null, parameters typed by a type variable, custom scalar arguments, recursive input objects and the WARN
17+
for unmapped input fields (`inputs`, `unmapped-inputs`, `generic-input-resolver`, `scalar-args`, `recursive-inputs`).
18+
- [Async resolvers and subscriptions](./async-and-subscriptions.md): `CompletableFuture`, suspend functions, and
19+
`Publisher` subscriptions (`async`).
20+
- [Generic wrappers](./generic-wrappers.md): wrappers and futures nested in lists and other wrappers, with and without a
21+
`ValueUnboxer`, and in suspend resolvers (`nested-wrappers`, `nested-wrappers-unboxer`, `nested-wrappers-suspend`).
22+
- [DataFetcherResult inside an Optional](./optional-data-fetcher-results.md): data, errors, empty, a list, the same type
23+
returned another way, and the nested-result rejection (`optional-results`, `optional-results-mixed`,
24+
`optional-results-list`, `optional-results-nested`).
25+
- [Interfaces and unions](./interfaces-and-unions.md): runtime type resolution through the dictionary, including a class
26+
whose name differs from the type, and a union that is only a member of another union (`polymorphism`,
27+
`nested-unions`).
28+
- [Directives and relay connections](./directives-and-relay.md): `SchemaDirectiveWiring`, `@deprecated`, `@connection`
29+
type generation, directives and `@specifiedBy` on scalars, wirings on recursive and cross-referencing types, applied
30+
versus legacy directive lists, undeclared directives and invalid applications (`directives`, `scalar-directives`,
31+
`wiring-shapes`, `directive-drift`, `directive-drift-undeclared`, `directives-invalid`).
32+
- [Schema parser options](./schema-options.md): `missingResolverDataFetcherProvider`
33+
(`options`).
34+
- [Type extensions](./type-extensions.md): fields, interfaces, members, values and directives of every kind of extension,
35+
the repeat and kind-mismatch warnings, repeated object and input fields, and sealed subclasses found through
36+
extensions (`type-extensions`, `type-extensions-repeated-fields`, `type-extensions-sealed`).
37+
- [Proxied resolvers](./proxies.md): Spring JDK dynamic and CGLIB proxies, and the warning for fields a JDK proxy can't
38+
call (`jdk-proxy`, `jdk-proxy-cglib`, `jdk-proxy-plain`).
39+
- [Context and environment parameters](./context-and-environment.md): `contextClass`, `GraphQLContext` and
40+
`DataFetchingEnvironment` after the schema arguments, in any order, the misbound-argument warning, and resolver methods
41+
without the source parameter (`context-and-environment`, `context-and-environment-invalid`, `context-misbound`,
42+
`sourceless`, `sourceless-shadowed`, `sourceless-unimplemented`, `sourceless-misbound`).
43+
44+
Not mapped yet: field visibility, per-field object mappers, the Guice, Javassist and Weld proxy handlers,
45+
`includeUnusedTypes`, and comment descriptions. Add a scenario and a feature entry when a change touches one of them.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Arguments and input types
2+
3+
Resolver methods take GraphQL arguments as ordinary parameters, in SDL order. graphql-java-tools converts scalars, enums,
4+
lists and input objects into the parameter's declared class, applies SDL default values, and passes
5+
`DataFetchingEnvironment` when it is the last parameter. An input object can refer to itself, or to another input object
6+
that refers back. With `inputArgumentOptionalDetectOmission`, an `Optional` parameter tells an omitted argument (`null`)
7+
from an explicit `null` (`Optional.empty()`).
8+
9+
## Sub-features
10+
11+
- `args-defaults` applies an argument's SDL default when the operation omits it.
12+
- `args-enum-list` converts `[Genre!]` literals into a `List<Genre>` of a Kotlin enum.
13+
- `args-env` passes `DataFetchingEnvironment` as the trailing parameter.
14+
- `args-input-object` maps a nested input object into data classes, including input field defaults.
15+
- `args-optional-omission` passes `null` for an omitted argument, `Optional.empty()` for an explicit null, and
16+
`Optional.of` for a value.
17+
- `args-invalid-enum` rejects an unknown enum literal during validation, before any resolver runs.
18+
- `args-unmapped-warn` logs a WARN at build for an input field the argument's class has no property for, here a
19+
misspelled property under an `Optional`.
20+
- `args-unmapped-ignored` doesn't report a field the property's `@JsonIgnoreProperties` ignores, here on an `Optional`
21+
property.
22+
- `args-type-variable` converts an argument whose parameter is typed by the resolver superclass's type variable into the
23+
class the subclass binds it to.
24+
- `args-scalars` passes a custom scalar's coerced object through unconverted, also when it's a Kotlin class without visible
25+
properties inside an input object, converts `ID` into a `Long` parameter, and converts `[[String]]` into a
26+
`List<Set<String>>` parameter.
27+
- `args-recursive` converts an input object that refers to itself, and two that refer to each other, through lists, nested
28+
lists and non-null types into data classes at every depth. It also builds a directive whose arguments are an input
29+
object, an enum with a default and a list.
30+
31+
## Expected results
32+
33+
- **Run.** `run inputs`. Exit `0`. `summary.txt` shows `errors=0` for `01` to
34+
`03` and `errors=1` for `04-invalid-enum`.
35+
- **Defaults, enums, env.** `01-search.json` has
36+
`data.defaults = "term=dune limit=10 genres=null field=search"` and
37+
`data.explicit = "term=dune limit=2 genres=[SCIENCE, HISTORY] field=search"`.
38+
- **Omitted vs null.** `02-nickname.json` has `omitted = "omitted"`, `explicitNull = "explicit null"` and
39+
`given = "value Bilbo"`.
40+
- **Input objects.** `03-add-book.json` (variables in `03-add-book.variables.json`) has `data.addBook` equal to
41+
`{"title": "Cosmos", "genre": "SCIENCE", "tags": ["space", "classic"], "pages": 396, "language": "en"}`. `language`
42+
comes from the input field default. `data.defaults` is `{"genre": "FICTION", "tags": [], "pages": null}`.
43+
- **Invalid enum.** `04-invalid-enum.json` has no `data`, and one error whose message starts with
44+
`Validation error (WrongType@[search])` and names `POETRY`.
45+
- **Unmapped input fields.** `run unmapped-inputs`. Exit `0`. `probe.log` has
46+
exactly one `UnmappedInputFieldChecker` WARN, starting `Input field 'ItemInput.name' has no matching property in
47+
scenarios.ItemInput` and listing `Known properties: nmae`. There is no WARN for `InnerInput.legacy`.
48+
`01-ignored.json` has `data.ignored = "a"`. `02-typo.json` has one error containing
49+
`Unrecognized property "name" (class scenarios.ItemInput)` (`Unrecognized field` before Jackson 3, in 14.x), which shows
50+
the reported field really fails.
51+
- **Type variable parameters.** `run generic-input-resolver`. Exit `0`.
52+
`summary.txt` shows `errors=0` for both operations. `02-generic.json` has
53+
`data.generic = "generic got GreetingInput(name=a)"`, and `01-plain.json` has
54+
`data.plain = "plain got GreetingInput(name=a)"`.
55+
- **Scalar arguments.** `run scalar-args`. Exit `0`. `summary.txt` shows
56+
`errors=0` for the first five operations. `01-custom-scalar.json` has `data.tag = "tag kotlin"` and
57+
`data.tags = "tags [a, b]"` (`Tag` has no constructor Jackson can use, so this only works when the value is passed
58+
through). `02-id.json` has `data.id = "id 43 (long)"`. `03-nested-sets.json` has
59+
`data.nestedSets = "sets [[a, b], [c]] sizes [2, 1]"`. `04-nested-lists.json` has
60+
`data.nestedLists = "lists [[a, a, b], [c]]"`. `05-empty-kotlin-scalar.json` has `data.tokenInput = "token input"`.
61+
`06-marked-empty-kotlin-scalars.json` has one error and `07-optional-marked-empty-kotlin-scalars.json` two, all containing
62+
`missing type id property '@class'` or `Cannot deserialize value of type`. Those scalars fail rather than reach the resolver
63+
as a default instance.
64+
- **Recursive inputs.** `run recursive-inputs`. Exit `0`, `errors=0` for both operations and an empty `probe.log`.
65+
`01-describe.json` (variables in `01-describe.variables.json`) has `data.names = ["a", "b"]`. `data.describe` starts
66+
`TreeFilter(name=root, and=[TreeFilter(name=a,` and ends `siblings=[[ChildFilter(parent=null, siblings=null, depth=4)],
67+
[]], depth=3))`. `data.literal` is `TreeFilter(name=x, and=null, not=null, child=ChildFilter(parent=null,
68+
siblings=[[ChildFilter(parent=null, siblings=null, depth=2)]], depth=1))`. `schema.graphqls` has `siblings:
69+
[[ChildFilter!]!]` and `directive @limit(labels: [String!], range: RangeInput!, unit: LimitUnit = ITEMS) on
70+
FIELD_DEFINITION | ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION`. In `02-introspect.json`, `limit` has `range` of
71+
`RangeInput!`, `unit` of `LimitUnit` with default `ITEMS`, and `labels` of `[String!]`.
72+
73+
## Gotchas
74+
75+
- Arguments bind by position, not name. A resolver whose parameters are in a different order than the SDL still builds
76+
when the types line up, and returns swapped values.
77+
- Without `inputArgumentOptionalDetectOmission`, an omitted argument and an explicit null both arrive as
78+
`Optional.empty()`. This scenario turns the option on. Prove the default behavior in a separate scenario.
79+
- `04-invalid-enum` fails in graphql-java validation. It proves the generated enum type, not the resolver's conversion.
80+
- The unmapped input field check comes from PR #857. On a checkout without it, `unmapped-inputs` still exits `0` with the
81+
same JSON, but `probe.log` has no `UnmappedInputFieldChecker` lines.
82+
- `02-typo` errors because the scenario uses the default `ObjectMapper`, which fails on unknown properties. It doesn't
83+
cover a mapper that ignores them.
84+
- The type variable fix comes from PR #882. On a checkout without it, `generic-input-resolver` still builds and exits
85+
`0`, but `02-generic.json` has `data: null` and an error containing `TypeVariableImpl cannot be cast to class
86+
java.lang.Class`.
87+
- The nested list fix comes from PR #891. On a checkout without it, `scalar-args` still exits `0`, but
88+
`03-nested-sets.json` has an error containing `ArrayList cannot be cast to class java.util.Set`.
89+
- The fix for a Kotlin scalar class without visible properties comes from issue #926. On a checkout without it,
90+
`05-empty-kotlin-scalar.json` has `data.tokenInput = "token default"`, since Jackson wrote the value as `{}` and read it
91+
back as a new instance. The same scalar written with a type id or an object id comes from issue #932. On a checkout
92+
without it, `07-optional-marked-empty-kotlin-scalars.json` has no errors and `"typed default"` and `"id default"`. The probe doesn't cover an `ObjectNode` parameter, which needs Jackson 3 on the probe's compile
93+
path. `CustomScalarInputTest` does.
94+
- `recursive-inputs` registers no directive wiring. `wiring-shapes` in `directives-and-relay.md` covers wirings on a
95+
recursive input.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Async resolvers and subscriptions
2+
3+
Resolvers can return a `CompletableFuture`, be Kotlin `suspend` functions (root resolvers and `GraphQLResolver<T>` field
4+
resolvers alike), or, for subscription fields, return a reactive-streams `Publisher`. The schema declares the plain
5+
result type (`String!`, `Int!`), and graphql-java-tools unwraps the async wrapper.
6+
7+
## Sub-features
8+
9+
- `async-future` resolves a field from a `CompletableFuture<String>`.
10+
- `async-suspend-root` resolves a root field from a `suspend fun` that suspends (`delay`).
11+
- `async-suspend-nested` resolves a list of objects from a `suspend fun`, and a field on each through a suspend
12+
`GraphQLResolver<Shipment>` method.
13+
- `async-subscription` streams a `Publisher<Int>` from a `GraphQLSubscriptionResolver`, one event per element, then
14+
completes.
15+
16+
## Expected results
17+
18+
- **Run.** `run async`. Exit `0`. `summary.txt` has
19+
`operation 01-query: errors=0` and `operation 02-subscription: errors=0 events=3`.
20+
- **Futures and suspend.** `01-query.json` has `data.future = "from a future"`,
21+
`data.suspended = "from a suspend function"`, and
22+
`data.shipments = [{"id": "s1", "status": "s1: delivered"}, {"id": "s2", "status": "s2: delivered"}]`.
23+
- **Subscription.** `02-subscription.json` is
24+
`{"events": [{"data": {"ticks": 1}}, {"data": {"ticks": 2}}, {"data": {"ticks": 3}}]}`, with no `errors` key and no
25+
`publisherError` entry.
26+
27+
## Gotchas
28+
29+
- Collection stops at stream completion or after 10 seconds. A publisher that never completes prints `subscription did
30+
not complete within 10 seconds` and records only the events seen so far, which is a finding, not a pass.
31+
- An error from the publisher shows up as a `{"publisherError": ...}` event, not under `errors`.
32+
- `--graphql-java` changes only the runtime graphql-java. The library jar is still the one compiled against the version
33+
in `pom.xml`.
34+
- The suspend timing isn't asserted. To prove a dispatcher or `coroutineContextProvider` change, add a field that
35+
reports `Thread.currentThread().name` or the coroutine context to a new scenario.

0 commit comments

Comments
 (0)