Skip to content

add add-graphql option includeSchemaDirecties - #1587

Open
cometkim wants to merge 1 commit into
hayes:mainfrom
cometkim:add-directives
Open

add add-graphql option includeSchemaDirecties#1587
cometkim wants to merge 1 commit into
hayes:mainfrom
cometkim:add-directives

Conversation

@cometkim

Copy link
Copy Markdown
Contributor

While I'm doing incremental migration to Pothos using the add-graphql plugin,

import SchemaBuilder from '@pothos/core';
import AddGraphQLPlugin from '@pothos/plugin-add-graphql';

import { filterSchema } from '@graphql-tools/utils';
import { schema as orignalSchema } from '#schema.ts';

const remainingSchema = filterSchema(originalSchema, { ... });

const builder = new SchemaBuilder({
  plugins: [AddGraphQLPlugin],
  add: {
    schema: remainingSchema,
  },
});

I noticed that directives from originalSchema are omitted. Even with printSchemaWithDirectives() from @graphql-tools/utils, it doesn't generate directives in the SDL.

This was important to me because I needed to verify that the new schema provided the same functionality (including the printer) as the existing schema.

I made this patch to fix it, but I'm not sure it can be merged upstream.

@changeset-bot

changeset-bot Bot commented Dec 29, 2025

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: e936ac1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel

vercel Bot commented Dec 29, 2025

Copy link
Copy Markdown

@cometkim is attempting to deploy a commit to the Michael Hayes' projects Team on Vercel.

A member of the Team first needs to authorize it.

@pkg-pr-new

pkg-pr-new Bot commented Dec 29, 2025

Copy link
Copy Markdown

Open in StackBlitz

@pothos/core

npm i https://pkg.pr.new/@pothos/core@1587

@pothos/plugin-add-graphql

npm i https://pkg.pr.new/@pothos/plugin-add-graphql@1587

@pothos/plugin-complexity

npm i https://pkg.pr.new/@pothos/plugin-complexity@1587

@pothos/plugin-dataloader

npm i https://pkg.pr.new/@pothos/plugin-dataloader@1587

@pothos/plugin-directives

npm i https://pkg.pr.new/@pothos/plugin-directives@1587

@pothos/plugin-drizzle

npm i https://pkg.pr.new/@pothos/plugin-drizzle@1587

@pothos/plugin-errors

npm i https://pkg.pr.new/@pothos/plugin-errors@1587

@pothos/plugin-example

npm i https://pkg.pr.new/@pothos/plugin-example@1587

@pothos/plugin-federation

npm i https://pkg.pr.new/@pothos/plugin-federation@1587

@pothos/plugin-grafast

npm i https://pkg.pr.new/@pothos/plugin-grafast@1587

@pothos/plugin-mocks

npm i https://pkg.pr.new/@pothos/plugin-mocks@1587

@pothos/plugin-prisma

npm i https://pkg.pr.new/@pothos/plugin-prisma@1587

@pothos/plugin-prisma-utils

npm i https://pkg.pr.new/@pothos/plugin-prisma-utils@1587

@pothos/plugin-relay

npm i https://pkg.pr.new/@pothos/plugin-relay@1587

@pothos/plugin-scope-auth

npm i https://pkg.pr.new/@pothos/plugin-scope-auth@1587

@pothos/plugin-simple-objects

npm i https://pkg.pr.new/@pothos/plugin-simple-objects@1587

@pothos/plugin-smart-subscriptions

npm i https://pkg.pr.new/@pothos/plugin-smart-subscriptions@1587

@pothos/plugin-sub-graph

npm i https://pkg.pr.new/@pothos/plugin-sub-graph@1587

@pothos/plugin-tracing

npm i https://pkg.pr.new/@pothos/plugin-tracing@1587

@pothos/plugin-validation

npm i https://pkg.pr.new/@pothos/plugin-validation@1587

@pothos/plugin-with-input

npm i https://pkg.pr.new/@pothos/plugin-with-input@1587

@pothos/plugin-zod

npm i https://pkg.pr.new/@pothos/plugin-zod@1587

@pothos/tracing-newrelic

npm i https://pkg.pr.new/@pothos/tracing-newrelic@1587

@pothos/tracing-opentelemetry

npm i https://pkg.pr.new/@pothos/tracing-opentelemetry@1587

@pothos/tracing-sentry

npm i https://pkg.pr.new/@pothos/tracing-sentry@1587

@pothos/tracing-xray

npm i https://pkg.pr.new/@pothos/tracing-xray@1587

commit: e936ac1

@hayes hayes left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I probably can't merge this in its current state, but I can look into supporting this properly.

What format are the directives in in your current schema that they don't show up in extensions with the current implementation?

The main issue with the current implementation is that I try to avoid dependencies in pothos wherever possible (with a few exceptions the only dep in pothos packages is a peer dependency on graphql)

@hayes

hayes commented Dec 31, 2025

Copy link
Copy Markdown
Owner

I just pushed up a change that adds astNode support to core, as well as copying astNode info for types added with the add-graphQL plugin.

This won't add the directive definitions to the schema, but it MAY remove the need for the extracting of directives and re-adding them as extensions

const { schema: addedSchema, includeSchemaDirectives = false } = this.builder.options.add ?? {};

if (includeSchemaDirectives && addedSchema) {
return addTypes(schema, [...addedSchema.getDirectives()]);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious if after the change I just published if this is the only part that is still needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the part for including the directive definition. And I noticed addTypes is required for rewiring duplicated definitions by the directive. But yeah, maybe manually redefining the directive is simpler.

It's worth noting that the add-graphql plugin doesn't handle this. I was confused.

@cometkim

cometkim commented Jan 5, 2026

Copy link
Copy Markdown
Contributor Author

What format are the directives in in your current schema that they don't show up in extensions with the current implementation?

originalSchema is parsed SDL by @graphql-tools/schema makeExecutableSchema()

@hayes

hayes commented Jan 10, 2026

Copy link
Copy Markdown
Owner

Still working on something for this. Hoping to have something this weekend. Directives are kinda weird and complex.

I got sucked down the rabbit hole a bit, but I think automatically adding referenced directives should make sense (as long as the directive plugin is also added)

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