Skip to content

Join GraphQL handlers on one field and declare GraphQL type names - #25

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

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

Conversation

@alefcastelo

Copy link
Copy Markdown
Member

What changes for the developer:

Several handlers on one field. Two handlers that call pet with other arguments or returns used to stop generate ("declare the same returns in every handler"). Now they are joined, the way the broker joins the same declarations from two files:

#[BidirektGraphqlConsumer(provider: 'petstore_api', query: 'pet', arguments: PetArgs::class, returns: ['nullable' => PetWithStatus::class])]
#[BidirektGraphqlConsumer(provider: 'petstore_api', query: 'pet', arguments: PetArgs::class, returns: ['nullable' => PetWithNickname::class])]
pet:
  arguments: PetArgs
  returns: [PetWithNicknameOrNull, PetWithStatusOrNull]

Names are de-duplicated and byte-sorted, ~ first for a handler without arguments (arguments: [~, PetArgs]), one distinct schema stays a plain value.

graphqlType. #[BidirektSchema(graphqlType: 'Pet')] or @bidirekt schema graphqlType=Pet on a class or enum writes name: Pet on its schema, so the check breaks when the provider's type has another name. Without it, a same-shape rename still doesn't break.

Built-in scalars. scalar: 'ID' / scalar:ID writes {type: scalar, name: ID}, which broker 0.6.0 now accepts; the hint for returns: 'ID' points to it.

Files:

  • src/Model/Protocols/Graphql/BlocksToMerged.php, Operation.php, src/Reader/Protocols/Graphql/ConsumedOperation.php, src/Protocols/GraphqlProtocol.php: operations carry lists and are joined instead of refused
  • src/Writer/Protocols/Graphql/BlockToYaml.php, src/Writer/YamlSequence.php, YamlMap.php, ContractToYaml.php, StringToYaml.php: write a flow list of names
  • src/BidirektSchema.php, src/Reader/SchemaClasses.php, ClassesToSchemas.php, FunctionsToSchemas.php, SchemaAnnotation.php, FieldOptions.php, TagArgumentsToOptions.php, src/Model/Protocols/Graphql/GraphqlExtra.php, src/Writer/Protocols/Graphql/FieldExtraToYaml.php: graphqlType
  • tests/: rejects-graphql-conflicting-handlers became graphql-consumer-joins-handlers; new graphql-consumer-joins-reads-of-one-field, graphql-type-names(-tags), rejects-malformed-graphql-type; unit tests and updated messages
  • tests/e2e/run.sh: the joined consumer publishes and breaks only on the field the provider lacks
  • README.md: joining, graphqlType, built-in scalars

🤖 Generated with Claude Code

Handlers that call the same field with other arguments or returns no longer
stop generate: each distinct schema is written once, as a list when there are
several (`returns: [PetWithName, PetWithStatus]`, `arguments: [~, PetArgs]`).

#[BidirektSchema(graphqlType: 'Pet')] and `@bidirekt schema graphqlType=Pet`
write `name: Pet` on an object or enum schema, and `scalar: 'ID'` is the way
to send a built-in GraphQL scalar by its name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alefcastelo
alefcastelo merged commit 112e094 into main Dec 1, 2026
10 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