
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
@pothos/plugin-add-graphql
Advanced tools
A Pothos plugin for adding existing GraphQL types to a Pothos schema
This plugin makes it easy to integrate GraphQL types from existing schemas into your Pothos API
It can be used for incremental migrations from nexus, graphql-tools, or any other JS/TS executable schema.
yarn add @pothos/plugin-add-graphql
import AddGraphQLPlugin from '@pothos/plugin-add-graphql';
const builder = new SchemaBuilder({
plugins: [AddGraphQLPlugin],
});
There are 2 ways you can reference existing types.
Adding types to the builder will automatically include the types in your schema when it's built. Types will only be added if no existing type of the same name is added to the builder before building the schema.
Adding types recursively adds any other types that the added type depends in it's fields, interfaces, or union members.
import { existingSchema } from './existing-schema-location';
const builder = new SchemaBuilder({
plugins: [AddGraphQLPlugin],
add: {
// You can add individual types
// This accepts Any GraphQLNamedType (Objects, Interface, Unions, Enums, Scalars, and InputObjects)
types: [schema.getType('User'), schema.getType('Post')],
// Or you can add an entire external schema
schema: externalSchema,
},
});
Adding types by themselves isn't very useful, so you'll probably want to be able to reference them when defining fields in your schema. To do this, you can add them to the builders generic Types.
This currently only works for Object, Interface, and Scalar types. For other types, use the
builder methods below to create refs to the added types.
import { existingSchema } from './existing-schema-location';
const builder = new SchemaBuilder<{
Objects: {
User: UserType;
};
Interfaces: {
ExampleInterface: { id: string };
};
Scalars: {
DateTime: {
Output: Date;
Input: Date;
};
};
}>({
plugins: [AddGraphQLPlugin],
add: {
types: [
existingSchema.getType('User'),
existingSchema.getType('ExampleInterface'),
existingSchema.getType('DateTime'),
],
},
});
builder.queryFields((t) => ({
user: t.field({ type: 'User', resolve: () => getUser() }),
exampleInterface: t.field({ type: 'ExampleInterface', resolve: () => getThings() }),
now: t.field({ type: 'DateTime', resolve: () => new Date() }),
}));
// Passing in a generic type is recommended to ensure type-safety
const UserRef = builder.addGraphQLObject<UserType>(
existingSchema.getType('User') as GraphQLObjectType,
{
// Optionally you can override the types name
name: 'AddedUser',
// You can also pass in any other options you can define for normal object types
description: 'This type represents Users',
},
);
const PostRef = builder.addGraphQLObject<{
id: string;
title: string;
content: string;
}>(existingSchema.getType('Post') as GraphQLObjectType, {
fields: (t) => ({
// remove existing title field from type
title: null,
// add new titleField
postTitle: t.exposeString('title'),
}),
});
You can then use the returned references when defining fields:
builder.queryFields((t) => ({
posts: t.field({
type: [PostRef],
resolve: () => loadPosts(),
}),
}));
const NodeRef = builder.addGraphQLInterface<NodeShape>(
existingSchema.getType('Node') as GraphQLInterfaceType,
{
// interface options
},
);
const SearchResult = builder.addGraphQLUnion<User | Post>(
existingSchema.getType('SearchResult') as GraphQLUnionType,
{
// union options
},
);
const OrderBy = builder.addGraphQLEnum<'Asc' | 'Desc'>(
existingSchema.getType('OrderBy') as GraphQLEnumType,
{
// enum options
},
);
const PostFilter = builder.addGraphQLInput<{ title?: string, tags? string[] }>(
existingSchema.getType('PostFilter') as GraphQLInputObjectType,
{
// input options
},
);
This plugin does not add a new method for scalars, because Pothos already has a method for adding existing scalar types.
builder.addScalarType('DateTime', existingSchema.getType('DateTime') as GraphQLScalar, {
// scalar options
});
FAQs
A Pothos plugin for adding existing GraphQL types to a Pothos schema
The npm package @pothos/plugin-add-graphql receives a total of 44,395 weekly downloads. As such, @pothos/plugin-add-graphql popularity was classified as popular.
We found that @pothos/plugin-add-graphql demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.