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: [existingSchema.getType('User'), existingSchema.getType('Post')], // Or you can add an entire external schema schema: existingSchema, },});
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.
// Passing in a generic type is recommended to ensure type-safetyconst 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: