Skip to content

feat: schema contract composition#180

Merged
n1ru4l merged 5 commits intomainfrom
feat-compose-schema-contract
Sep 12, 2025
Merged

feat: schema contract composition#180
n1ru4l merged 5 commits intomainfrom
feat-compose-schema-contract

Conversation

@n1ru4l
Copy link
Copy Markdown
Contributor

@n1ru4l n1ru4l commented Sep 12, 2025

Adds utility for composing a schema contract. We already had this code within Hive console, but it makes sense to move this here so people that do not use a schema registry can benefit from it as well.

See graphql-hive/console#6964

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 12, 2025

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@theguild/federation-composition 0.20.0-alpha-20250912121204-92648c530f28858478012254a58b75137cd1ccaa npm ↗︎ unpkg ↗︎

@n1ru4l n1ru4l force-pushed the feat-compose-schema-contract branch from f1f7b4c to 0c553ba Compare September 12, 2025 11:52
@n1ru4l n1ru4l requested a review from kamilkisiela September 12, 2025 11:52
@n1ru4l n1ru4l force-pushed the feat-compose-schema-contract branch from 57c22b0 to 92648c5 Compare September 12, 2025 12:11
@n1ru4l n1ru4l merged commit a208f1c into main Sep 12, 2025
4 checks passed
@n1ru4l n1ru4l deleted the feat-compose-schema-contract branch September 12, 2025 22:34
n1ru4l pushed a commit that referenced this pull request Sep 15, 2025
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @theguild/federation-composition@0.20.0

### Minor Changes

-
[#180](#180)
[`a208f1c`](a208f1c)
Thanks [@n1ru4l](https://github.com/n1ru4l)! - Add
`composeSchemaContract` function for composing schema contracts.

    Running the following script:

    ```ts
import { composeSchemaContract } from
"@theguild/federation-composition";
    import { parse } from "graphql";

    const result = composeSchemaContract(
      [
        {
          name: "a",
          typeDefs: parse(/* GraphQL */ `
            type Query {
              a: String @tag(name: "public")
            }
          `),
          url: "a.localhost",
        },
        {
          name: "b",
          typeDefs: parse(/* GraphQL */ `
            type Query {
              b: String
            }
          `),
          url: "b.localhost",
        },
      ],
      /** Tags to include and exclude */
      {
        include: new Set(["public"]),
        exclude: new Set(),
      },
      /** Exclude unreachable types */
      true,
    );

    console.log(result.publicSdl);
    ```

Will result in the output containing only the fields tagged with
`public`:

    ```graphql
    type Query {
      a: String!
    }
    ```

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
n1ru4l pushed a commit that referenced this pull request Sep 18, 2025
This fixes a small issue with external fields not checking if
`@external` is on the type/interface.
Previously @ graphql-hive/console#6907
But the code was migrated here in
#180
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.

2 participants