Skip to content

Join GraphQL handlers on one field and write GraphQL type names - #31

Merged
alefcastelo merged 1 commit into
mainfrom
graphql-golden-sdk-ts
Dec 1, 2026
Merged

alefcastelo merged 1 commit into
mainfrom
graphql-golden-sdk-ts

Conversation

@alefcastelo

Copy link
Copy Markdown
Member

Broker 0.6.0 takes a list in returns and arguments, and a name on GraphQL scalars, objects and enums. This PR makes generate write both.

Handlers on the same field are joined. Before this change, two handlers reading query pet with different returns or arguments stopped generate with "declare the same returns in every handler". Now they generate one field. It lists every distinct schema, de-duplicated and sorted, with ~ for a handler that passes no arguments. A single schema is still written as a plain value.

@BidirektGraphqlConsumer({ provider: 'petstore_api', query: 'pet', arguments: PetArgs, returns: PetName })
name() {}

@BidirektGraphqlConsumer({ provider: 'petstore_api', query: 'pet', returns: PetSummary })
summary() {}
pet:
  arguments: [~, PetArgs]
  returns: [PetName, PetSummary]

graphqlType is a new option on @BidirektSchema({ graphqlType: 'Pet' }) and on @bidirekt schema graphqlType=Pet, above a class, an interface, an object type or a string enum. It writes name: Pet on the schema, so the call breaks when the provider renames that type. Before, there was no way to declare the type name.

Built-in scalars: { scalar: 'ID' } and scalar=ID write type: scalar, name: ID. The same works for String, Int, Float and Boolean. That accepts the provider's ID and breaks on String, while 'string' accepts both. The SDK already wrote these. The broker accepts them since 0.6.0, and the README now says so.

Files

  • src/model/protocols/graphql/contract.ts: Operation.arguments and returns become lists (null = no arguments).
  • src/model/protocols/graphql/blocks-to-merged.ts: groups the handlers of a field instead of refusing them.
  • src/model/protocols/graphql/block-to-references.ts: walks every schema of the lists.
  • src/writer/protocols/graphql/block-to-yaml.ts: writes a plain value or a sorted flow list.
  • src/reader/schema-classes.ts, src/reader/tag-schemas.ts, src/model/contract.ts, src/writer/contract-to-yaml.ts, packages/typescript-sdk/src/index.ts: the graphqlType option, written as name.
  • tests/fixtures/rejects-graphql-conflicting-handlers becomes the success fixture graphql-consumer-joins-handlers. There are new fixtures graphql-type-names and graphql-type-names-tags, and the key lists in six error fixtures now include graphqlType.
  • tests/e2e/run.sh: two handlers read query pet, and one reads nickname, which the provider lacks. can-i-deploy breaks only on PetNickname.nickname. The declared Pet, ID and Int pass.
  • README.md: joining, graphqlType and the built-in scalar names.

🤖 Generated with Claude Code

Handlers that call the same query or mutation with different returns or
arguments now generate one field with lists, instead of stopping generate.
graphqlType on a schema writes its GraphQL type name, and the scalar option
accepts the built-in ID, String, Int, Float and Boolean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alefcastelo
alefcastelo merged commit ab9a831 into main Dec 1, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant