### Install and Run Example Source: https://github.com/hayes/pothos/blob/main/examples/fastify-mercurius/README.md Install dependencies and start the Fastify server. Access the GraphiQL interface at http://localhost:3000/graphiql. ```sh pnpm install pnpm start ``` -------------------------------- ### Run Example Applications Source: https://github.com/hayes/pothos/blob/main/CONTRIBUTING.md Navigate to an example application directory and use these commands to start it. Use 'pnpm start' for a standard run or 'pnpm dev' if the example supports a development/watch mode. ```bash cd examples/path-to-example-app pnpm start # or pnpm dev # If the example supports a dev/watch mode ``` -------------------------------- ### Example Builder Setup for Use Cases Source: https://github.com/hayes/pothos/blob/main/website/content/docs/plugins/scope-auth.mdx A sample SchemaBuilder configuration demonstrating the setup of AuthScopes and the authScopes initializer function, as assumed in the 'Use cases' section. ```typescript const builder = new SchemaBuilder<{ // Types used for scope parameters AuthScopes: { public: boolean; employee: boolean; deferredScope: boolean; customPerm: MyPerms; }; }>({ plugins: [ScopeAuthPlugin], authScopes: async (context) => ({ public: !!context.User, employee: await context.User.isEmployee(), deferredScope: () => context.User.isEmployee(), customPerm: (perm) => context.permissionService.hasPermission(context.User, perm), }), }); ``` -------------------------------- ### Example Builder Setup for Use Cases Source: https://github.com/hayes/pothos/blob/main/packages/plugin-scope-auth/README.md This is an example builder setup assumed for the use cases section. It defines authorization scopes including boolean, deferred, and parameterized scopes. ```typescript const builder = new SchemaBuilder<{ // Types used for scope parameters AuthScopes: { public: boolean; employee: boolean; deferredScope: boolean; customPerm: MyPerms; }; }>({ plugins: [ScopeAuthPlugin], authScopes: async (context) => ({ public: !!context.User, employee: await context.User.isEmployee(), deferredScope: () => context.User.isEmployee(), customPerm: (perm) => context.permissionService.hasPermission(context.User, perm), }), }); ``` -------------------------------- ### Start Server Source: https://github.com/hayes/pothos/blob/main/examples/open-telemetry/README.md Starts the Pothos GraphQL server. This command assumes the project dependencies have been installed. ```bash pnpm start ``` -------------------------------- ### Basic Sentry Tracing Setup Source: https://github.com/hayes/pothos/blob/main/website/content/docs/plugins/tracing.mdx Configures Pothos to use the Sentry tracing plugin. This example shows how to create a wrapper for resolvers and integrate it into the builder, with options for including arguments, source, and ignoring errors. ```ts import SchemaBuilder from '@pothos/core'; import TracingPlugin, { isRootField } from '@pothos/plugin-tracing'; import { createSentryWrapper } from '@pothos/tracing-sentry'; const traceResolver = createSentryWrapper({ includeArgs: true, includeSource: true, }); export const builder = new SchemaBuilder({ plugins: [TracingPlugin], tracing: { default: (config) => isRootField(config), wrap: (resolver, options) => traceResolver(resolver, options), }, }); ``` -------------------------------- ### Install With-Input Plugin Source: https://github.com/hayes/pothos/blob/main/packages/plugin-with-input/README.md Install the plugin using npm. ```bash npm install --save @pothos/plugin-with-input ``` -------------------------------- ### Basic Error Handling Setup Source: https://github.com/hayes/pothos/blob/main/packages/plugin-errors/README.md Demonstrates setting up the Errors plugin with a default error interface and base error type. Includes examples of handling simple errors and custom errors like LengthError. ```typescript import ErrorsPlugin from '@pothos/plugin-errors'; const builder = new SchemaBuilder({ plugins: [ErrorsPlugin], errors: { defaultTypes: [Error], }, }); const ErrorInterface = builder.interfaceRef('Error').implement({ fields: (t) => ({ message: t.exposeString('message'), }), }); builder.objectType(Error, { name: 'BaseError', interfaces: [ErrorInterface], }); class LengthError extends Error { minLength: number; constructor(minLength: number) { super(`string length should be at least ${minLength}`); this.minLength = minLength; this.name = 'LengthError'; } } builder.objectType(LengthError, { name: 'LengthError', interfaces: [ErrorInterface], fields: (t) => ({ minLength: t.exposeInt('minLength'), }), }); builder.queryType({ fields: (t) => ({ // Simple error handling just using base error class hello: t.string({ errors: {}, args: { name: t.arg.string({ required: true }), }, resolve: (parent, { name }) => { if (!name.startsWith(name.slice(0, 1).toUpperCase())) { throw new Error('name must be capitalized'); } return `hello, ${name || 'World'}`; }, }), // Handling custom errors helloWithMinLength: t.string({ errors: { types: [LengthError], }, args: { name: t.arg.string({ required: true }), }, resolve: (parent, { name }) => { if (name.length < 5) { throw new LengthError(5); } return `hello, ${name || 'World'}`; }, }), }), }); ``` -------------------------------- ### Install Prisma Plugin Source: https://github.com/hayes/pothos/blob/main/website/content/docs/plugins/prisma/setup.mdx Install the Prisma plugin using npm. ```bash npm install --save @pothos/plugin-prisma ``` -------------------------------- ### Basic New Relic Tracing Setup Source: https://github.com/hayes/pothos/blob/main/website/content/docs/plugins/tracing.mdx Configures Pothos to use the New Relic tracing plugin. This example shows how to create a wrapper for resolvers and integrate it into the builder. ```ts import SchemaBuilder from '@pothos/core'; import TracingPlugin, { isRootField } from '@pothos/plugin-tracing'; import { createNewrelicWrapper } from '@pothos/tracing-newrelic'; const wrapResolver = createNewrelicWrapper({ includeArgs: true, includeSource: true, }); export const builder = new SchemaBuilder({ plugins: [TracingPlugin], tracing: { default: (config) => isRootField(config), wrap: (resolver) => wrapResolver(resolver), }, }); ``` -------------------------------- ### Install Tracing Plugin Source: https://github.com/hayes/pothos/blob/main/packages/plugin-tracing/README.md Install the tracing plugin using yarn. ```bash yarn add @pothos/plugin-tracing ``` -------------------------------- ### Install Dependencies and Build Packages Source: https://github.com/hayes/pothos/blob/main/CONTRIBUTING.md Run these commands to install all project dependencies and then build all packages. ```bash pnpm install pnpm build ``` -------------------------------- ### Install Mocks Plugin Source: https://github.com/hayes/pothos/blob/main/website/content/docs/plugins/mocks.mdx Install the Mocks plugin using npm. ```package-install npm install --save @pothos/plugin-mocks ``` -------------------------------- ### Install Smart Subscriptions Plugin Source: https://github.com/hayes/pothos/blob/main/packages/plugin-smart-subscriptions/README.md Install the smart subscriptions plugin using npm. ```bash npm install --save @pothos/plugin-smart-subscriptions ``` -------------------------------- ### Install Mocks Plugin Source: https://github.com/hayes/pothos/blob/main/packages/plugin-mocks/README.md Install the Mocks plugin using yarn. ```bash yarn add @pothos/plugin-mocks ``` -------------------------------- ### Install Dependencies Source: https://github.com/hayes/pothos/blob/main/examples/open-telemetry/README.md Installs the necessary project dependencies using pnpm. Ensure pnpm is installed globally. ```bash pnpm install ``` -------------------------------- ### Install Scope Auth Plugin Source: https://github.com/hayes/pothos/blob/main/packages/plugin-scope-auth/README.md Install the scope-auth plugin using yarn. ```bash yarn add @pothos/plugin-scope-auth ``` -------------------------------- ### Install Simple Objects Plugin Source: https://github.com/hayes/pothos/blob/main/website/content/docs/plugins/simple-objects.mdx Install the Simple Objects Plugin using npm. ```bash npm install --save @pothos/plugin-simple-objects ``` -------------------------------- ### Install Tracing Plugin Source: https://github.com/hayes/pothos/blob/main/website/content/docs/plugins/tracing.mdx Install the Pothos Tracing plugin using npm. ```bash npm install --save @pothos/plugin-tracing ``` -------------------------------- ### Setup Directives Plugin with GraphQL Tools Source: https://github.com/hayes/pothos/blob/main/packages/plugin-directives/README.md Set up the directives plugin and integrate with graphql-rate-limit-directive. This example demonstrates defining directive types, applying a directive to a query field, and transforming the schema. ```typescript import DirectivePlugin from '@pothos/plugin-directives'; import { rateLimitDirective } from 'graphql-rate-limit-directive'; const builder = new SchemaBuilder<{ Directives: { rateLimit: { locations: 'OBJECT' | 'FIELD_DEFINITION'; args: { limit: number, duration: number }; }; }; }>({ plugins: [DirectivePlugin], directives: { useGraphQLToolsUnorderedDirectives: true, } }); builder.queryType({ directives: { rateLimit: { limit: 5, duration: 60 }, }, fields: (t) => ({ hello: t.string({ resolve: () => 'world' }); }); }); const { rateLimitDirectiveTransformer } = rateLimitDirective(); const schema = rateLimitDirectiveTransformer(builder.toSchema()); ``` -------------------------------- ### Install Complexity Plugin Source: https://github.com/hayes/pothos/blob/main/packages/plugin-complexity/README.md Install the complexity plugin using yarn. ```bash yarn add @pothos/plugin-complexity ``` -------------------------------- ### Install Complexity Plugin Source: https://github.com/hayes/pothos/blob/main/website/content/docs/plugins/complexity.mdx Install the Pothos Complexity plugin using npm. ```bash npm install --save @pothos/plugin-complexity ``` -------------------------------- ### Install Apollo Server Source: https://github.com/hayes/pothos/blob/main/website/content/docs/plugins/federation.mdx Optionally install the Apollo Server package if you are using it for your server. ```bash npm install --save @apollo/server ``` -------------------------------- ### Install Add-GraphQL Plugin Source: https://github.com/hayes/pothos/blob/main/packages/plugin-add-graphql/README.md Install the @pothos/plugin-add-graphql package using yarn. ```bash yarn add @pothos/plugin-add-graphql ``` -------------------------------- ### Install SubGraph Plugin Source: https://github.com/hayes/pothos/blob/main/website/content/docs/plugins/sub-graph.mdx Install the SubGraph plugin using npm. ```bash npm install --save @pothos/plugin-sub-graph ``` -------------------------------- ### Install Federation Dependencies Source: https://github.com/hayes/pothos/blob/main/examples/prisma-federation/README.md Install the federation plugin, directives plugin, and @apollo/subgraph. You may also want to install @apollo/server. ```bash yarn add @pothos/plugin-federation @pothos/plugin-directives @apollo/subgraph yarn add @apollo/server ``` -------------------------------- ### Setup Directive Plugin and Apply Rate Limit Source: https://github.com/hayes/pothos/blob/main/website/content/docs/plugins/directives.mdx Configure the DirectivePlugin with schema types and apply a rate limit directive to a query type. This example demonstrates defining directive arguments and integrating with graphql-tools for schema transformation. ```typescript import DirectivePlugin from '@pothos/plugin-directives'; import { rateLimitDirective } from 'graphql-rate-limit-directive'; const builder = new SchemaBuilder<{ Directives: { rateLimit: { locations: 'OBJECT' | 'FIELD_DEFINITION'; args: { limit: number, duration: number }; }; }; }>({ plugins: [DirectivePlugin], directives: { useGraphQLToolsUnorderedDirectives: true, } }); builder.queryType({ directives: { rateLimit: { limit: 5, duration: 60 }, }, fields: (t) => ({ hello: t.string({ resolve: () => 'world' }); }); }); const { rateLimitDirectiveTransformer } = rateLimitDirective(); const schema = rateLimitDirectiveTransformer(builder.toSchema()); ``` -------------------------------- ### Install graphql-code-generator Packages Source: https://github.com/hayes/pothos/blob/main/website/content/docs/guide/generating-client-types.mdx Install the necessary packages for graphql-code-generator, including the CLI and client preset. ```bash npm install --save graphql npm install --save -D typescript @graphql-codegen/cli @graphql-codegen/client-preset ``` -------------------------------- ### Install Prisma Plugin Source: https://github.com/hayes/pothos/blob/main/packages/plugin-prisma/README.md Install the Prisma plugin for Pothos using yarn. ```bash yarn add @pothos/plugin-prisma ``` -------------------------------- ### Install Relay Plugin Source: https://github.com/hayes/pothos/blob/main/packages/plugin-relay/README.md Install the Relay plugin using npm. ```bash npm install --save @pothos/plugin-relay ``` -------------------------------- ### Install Pothos and GraphQL Yoga Source: https://github.com/hayes/pothos/blob/main/website/content/docs/guide/index.mdx Install the necessary packages for Pothos and GraphQL Yoga using npm. ```bash npm install --save @pothos/core graphql-yoga ``` -------------------------------- ### Install a Pothos Plugin Source: https://github.com/hayes/pothos/blob/main/website/content/docs/guide/using-plugins.mdx Install the scope-auth plugin using npm. This is the first step before importing and using the plugin. ```bash npm install --save @pothos/plugin-scope-auth ``` -------------------------------- ### Install SubGraph Plugin Source: https://github.com/hayes/pothos/blob/main/packages/plugin-sub-graph/README.md Install the SubGraph plugin using yarn. ```bash yarn add @pothos/plugin-sub-graph ``` -------------------------------- ### Install Simple Objects Plugin Source: https://github.com/hayes/pothos/blob/main/packages/plugin-simple-objects/README.md Install the Simple Objects Plugin using yarn. ```bash yarn add @pothos/plugin-simple-objects ``` -------------------------------- ### Install Validation Plugin and ArkType Source: https://github.com/hayes/pothos/blob/main/packages/plugin-validation/README.md Install the validation plugin and ArkType for schema validation. ```bash npm install --save @pothos/plugin-validation arktype ``` -------------------------------- ### Install Zod and Plugin Source: https://github.com/hayes/pothos/blob/main/packages/plugin-zod/README.md Install the necessary zod package and the Pothos zod plugin using npm. ```bash npm install --save zod @pothos/plugin-zod ``` -------------------------------- ### Install Add GraphQL Plugin Source: https://github.com/hayes/pothos/blob/main/website/content/docs/plugins/add-graphql.mdx Install the @pothos/plugin-add-graphql package using npm. ```bash npm install --save @pothos/plugin-add-graphql ``` -------------------------------- ### Install Validation Plugin and Zod Source: https://github.com/hayes/pothos/blob/main/packages/plugin-validation/README.md Install the validation plugin and Zod for schema validation. ```bash npm install --save @pothos/plugin-validation zod ``` -------------------------------- ### Install schema-ast Plugin for graphql-code-generator Source: https://github.com/hayes/pothos/blob/main/website/content/docs/guide/generating-client-types.mdx Install the 'schema-ast' plugin to enable the generation of a schema.graphql file. ```bash npm install --save -D @graphql-codegen/schema-ast ``` -------------------------------- ### Install Directives Plugin Source: https://github.com/hayes/pothos/blob/main/packages/plugin-directives/README.md Install the directives plugin using yarn. ```bash yarn add @pothos/plugin-directives ``` -------------------------------- ### Install Validation Plugin and Valibot Source: https://github.com/hayes/pothos/blob/main/packages/plugin-validation/README.md Install the validation plugin and Valibot for schema validation. ```bash npm install --save @pothos/plugin-validation valibot ``` -------------------------------- ### Install Drizzle Plugin Source: https://github.com/hayes/pothos/blob/main/packages/plugin-drizzle/README.md Install the Drizzle plugin and drizzle-orm using npm. ```bash npm install --save @pothos/plugin-drizzle drizzle-orm@beta ``` -------------------------------- ### Setup Simple Objects Plugin Source: https://github.com/hayes/pothos/blob/main/packages/plugin-simple-objects/README.md Set up the Pothos SchemaBuilder with the Simple Objects Plugin. ```typescript import SimpleObjectsPlugin from '@pothos/plugin-simple-objects'; const builder = new SchemaBuilder({ plugins: [SimpleObjectsPlugin], }); ``` -------------------------------- ### Setup Complexity Plugin Source: https://github.com/hayes/pothos/blob/main/packages/plugin-complexity/README.md Import and add the ComplexityPlugin to your SchemaBuilder. ```typescript import ComplexityPlugin from '@pothos/plugin-complexity'; const builder = new SchemaBuilder({ plugins: [ComplexityPlugin], }); ``` -------------------------------- ### Install Federation Plugin and Dependencies Source: https://github.com/hayes/pothos/blob/main/website/content/docs/plugins/federation.mdx Install the Pothos Federation plugin, directives plugin, and Apollo subgraph package using npm. ```bash npm install --save @pothos/plugin-federation @pothos/plugin-directives @apollo/subgraph ``` -------------------------------- ### Install Grafast Plugin and Grafast Source: https://github.com/hayes/pothos/blob/main/packages/plugin-grafast/README.md Install the Grafast plugin for Pothos and the Grafast library itself. Ensure Grafast version is compatible. ```bash npm install --save @pothos/plugin-grafast grafast@>=0.1.1-beta.24 ``` -------------------------------- ### Setup Smart Subscriptions Plugin Source: https://github.com/hayes/pothos/blob/main/website/content/docs/plugins/smart-subscriptions.mdx Configure the Pothos SchemaBuilder with the SmartSubscriptionsPlugin and its options. ```typescript import SchemaBuilder from '@pothos/core'; import SmartSubscriptionsPlugin from '@pothos/plugin-smart-subscriptions'; const builder = new SchemaBuilder({ plugins: [SmartSubscriptionsPlugin], smartSubscriptions: { debounceDelay: number | null; subscribe: (name: string, context: Context, cb: (err: unknown, data?: unknown) => void) => Promise | void; unsubscribe: (name: string, context: Context) => Promise | void; }, }); ``` -------------------------------- ### Install Dataloader and Pothos Plugin Source: https://github.com/hayes/pothos/blob/main/packages/plugin-dataloader/README.md Install the necessary dataloader package and the Pothos dataloader plugin using yarn. ```bash yarn add dataloader @pothos/plugin-dataloader ``` -------------------------------- ### Setup Basic OpenTelemetry Tracer Source: https://github.com/hayes/pothos/blob/main/packages/plugin-tracing/README.md Configure a simple OpenTelemetry tracer that logs spans to the console. This setup includes registering HTTP instrumentation and setting up a console span exporter. ```typescript import { diag, DiagConsoleLogger, DiagLogLevel, trace } from '@opentelemetry/api'; import { registerInstrumentations } from '@opentelemetry/instrumentation'; import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'; import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base'; import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node'; export const provider = new NodeTracerProvider({ spanProcessors: [new SimpleSpanProcessor(new ConsoleSpanExporter())] }); provider.register(); registerInstrumentations({ // Automatically create spans for http requests instrumentations: [new HttpInstrumentation({})], }); diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO); export const tracer = trace.getTracer('graphql'); ``` -------------------------------- ### Basic Tracing Setup Source: https://github.com/hayes/pothos/blob/main/packages/plugin-tracing/README.md Set up the Tracing plugin with default root field tracing and console logging for resolver duration. ```typescript import TracingPlugin, { wrapResolver, isRootField } from '@pothos/plugin-tracing'; const builder = new SchemaBuilder({ plugins: [TracingPlugin], tracing: { // Enable tracing for rootFields by default, other fields need to opt in default: (config) => isRootField(config), // Log resolver execution duration wrap: (resolver, options, config) => wrapResolver(resolver, (error, duration) => { console.log(`Executed resolver ${config.parentType}.${config.name} in ${duration}ms`); }), }, }); ``` -------------------------------- ### Initialize SchemaBuilder with Drizzle, Relay, and WithInput Plugins Source: https://github.com/hayes/pothos/blob/main/website/content/docs/plugins/drizzle.mdx Initialize Pothos SchemaBuilder with Drizzle, Relay, and WithInput plugins. This setup is common for many examples and provides advanced features. ```typescript import { drizzle } from 'drizzle-orm/...' import SchemaBuilder from '@pothos/core' import DrizzlePlugin from '@pothos/plugin-drizzle' import RelayPlugin from '@pothos/plugin-relay' import WithInputPlugin from '@pothos/plugin-with-input' import { getTableConfig } from 'drizzle-orm/sqlite-core' import { relations } from './db/relations' const db = drizzle({ client, relations }); export interface PothosTypes { DrizzleRelations: typeof relations; } const builder = new SchemaBuilder({ plugins: [RelayPlugin, WithInputPlugin, DrizzlePlugin], drizzle: { client: db, getTableConfig, relations, }, }); ``` -------------------------------- ### Setup Pothos Builder with SubGraph Plugin Source: https://github.com/hayes/pothos/blob/main/packages/plugin-sub-graph/README.md Configure the Pothos SchemaBuilder to use the SubGraphPlugin and define available subgraphs. This example shows how to set up default behaviors for type and field inheritance. ```typescript import SubGraphPlugin from '@pothos/plugin-sub-graph'; const builder = new SchemaBuilder<{ SubGraphs: 'Public' | 'Internal'; }>({ plugins: [SubGraphPlugin], subGraphs: { defaultForTypes: [], fieldsInheritFromTypes: true, }, }); ``` -------------------------------- ### Create a Basic GraphQL Server with Pothos Source: https://github.com/hayes/pothos/blob/main/packages/core/README.md This example demonstrates how to set up a simple GraphQL server using Pothos core and GraphQL Yoga. It defines a basic 'hello' query that accepts an optional name argument. ```typescript import { createServer } from 'node:http'; import { createYoga } from 'graphql-yoga'; import SchemaBuilder from '@pothos/core'; const builder = new SchemaBuilder({}); builder.queryType({ fields: (t) => ({ hello: t.string({ args: { name: t.arg.string(), }, resolve: (parent, { name }) => `hello, ${name || 'World'}`, }), }), }); const yoga = createYoga({ schema: builder.toSchema(), }); const server = createServer(yoga); server.listen(3000); ``` -------------------------------- ### Basic Errors Plugin Setup and Example Usage Source: https://github.com/hayes/pothos/blob/main/packages/plugin-errors/README.md Set up the Errors plugin with a schema builder and define a query field that can throw custom errors. Ensure your tsconfig.json targets es6 or higher. ```typescript import ErrorsPlugin from '@pothos/plugin-errors'; const builder = new SchemaBuilder({ plugins: [ErrorsPlugin], errors: { defaultTypes: [], // onResolvedError: (error) => console.error('Handled error:', error), }, }); builder.objectType(Error, { name: 'Error', fields: (t) => ({ message: t.exposeString('message'), }), }); builder.queryType({ fields: (t) => ({ hello: t.string({ errors: { types: [Error], }, args: { name: t.arg.string({ required: false }), }, resolve: (parent, { name }) => { if (name.slice(0, 1) !== name.slice(0, 1).toUpperCase()) { throw new Error('name must be capitalized'); } return `hello, ${name || 'World'}`; }, }), }), }); ``` -------------------------------- ### Basic Hello World GraphQL Server Source: https://github.com/hayes/pothos/blob/main/README.md Sets up a basic GraphQL server using Pothos and GraphQL Yoga. This example demonstrates creating a simple query field 'hello' that accepts an optional name argument. ```typescript import { createYoga } from 'graphql-yoga'; import { createServer } from 'node:http'; import SchemaBuilder from '@pothos/core'; const builder = new SchemaBuilder({}); builder.queryType({ fields: (t) => ({ hello: t.string({ args: { name: t.arg.string(), }, resolve: (parent, { name }) => `hello, ${name || 'World'}`, }), }), }); const yoga = createYoga({ schema: builder.toSchema(), }); const server = createServer(yoga); server.listen(3000); ``` -------------------------------- ### Setup Schema Builder with SubGraph Plugin Source: https://github.com/hayes/pothos/blob/main/website/content/docs/plugins/sub-graph.mdx Configure the SchemaBuilder with the SubGraphPlugin and define available subgraphs. This example shows how to create separate schemas for 'Public' and 'Internal' subgraphs, as well as combined or intersection schemas. ```typescript import SubGraphPlugin from '@pothos/plugin-sub-graph'; const builder = new SchemaBuilder<{ SubGraphs: 'Public' | 'Internal'; }>({ plugins: [SubGraphPlugin], subGraphs: { defaultForTypes: [], fieldsInheritFromTypes: true, }, }); //in another file: const schema = builder.toSchema(); const publicSchema = builder.toSchema({ subGraph: 'Public' }); const internalSchema = builder.toSchema({ subGraph: 'Internal' }); // You can also build a graph containing multiple subgraphs: const combinedSchema = builder.toSchema({ subGraph: ['Internal', 'Public'] }); // Or create a graph of the intersection between multiple subgraphs: const allSchema = builder.toSchema({ subGraph: { all: ['Internal', 'Public'] } }); ``` -------------------------------- ### Basic Prisma Plugin Setup Source: https://github.com/hayes/pothos/blob/main/packages/plugin-prisma/README.md Initialize SchemaBuilder with the PrismaPlugin, providing a PrismaClient instance and enabling Prisma-specific options. ```typescript import SchemaBuilder from '@pothos/core'; import { PrismaClient } from '@prisma/client'; import PrismaPlugin from '@pothos/plugin-prisma'; // This is the default location for the generator, but this can be // customized as described above. // Using a type only import will help avoid issues with undeclared // exports in esm mode import type PrismaTypes from '@pothos/plugin-prisma/generated'; const prisma = new PrismaClient({}); const builder = new SchemaBuilder<{ PrismaTypes: PrismaTypes; }>({ plugins: [PrismaPlugin], prisma: { client: prisma, // defaults to false, uses /// comments from prisma schema as descriptions // for object types, relations and exposed fields. // descriptions can be omitted by setting description to false exposeDescriptions: boolean | { models: boolean, fields: boolean }, // use where clause from prismaRelatedConnection for totalCount (defaults to true) filterConnectionTotalCount: true, // warn when not using a query parameter correctly onUnusedQuery: process.env.NODE_ENV === 'production' ? null : 'warn', }, }); ``` -------------------------------- ### Setup with Async Iterator Helper Source: https://github.com/hayes/pothos/blob/main/packages/plugin-smart-subscriptions/README.md Configure smart subscriptions using a helper function for async iterators, integrating with a pubsub instance. ```typescript const builder = new SchemaBuilder({ smartSubscriptions: { ...subscribeOptionsFromIterator((name, { pubsub }) => { return pubsub.asyncIterableIterator(name); }), }, }); ``` -------------------------------- ### Basic Pothos Builder Setup with Prisma Source: https://github.com/hayes/pothos/blob/main/website/content/docs/plugins/prisma/setup.mdx Set up the Pothos builder with the Prisma plugin, providing the Prisma client and DMMF data. ```typescript import SchemaBuilder from '@pothos/core'; import { PrismaClient } from '@prisma/client'; import PrismaPlugin from '@pothos/plugin-prisma'; import type PrismaTypes from '../lib/pothos-prisma-types'; // path to generated types, specified in your prisma.schema import { getDatamodel } from '../lib/pothos-prisma-types'; const prisma = new PrismaClient({}); const builder = new SchemaBuilder<{ PrismaTypes: PrismaTypes; }>({ plugins: [PrismaPlugin], prisma: { client: prisma, // This give pothos information about your tables, relations, and indexes to help it generate optimal queries at runtime. // This used to be attached to the prisma client, but has been removed in most runtimes/modes to reduce bundle size. dmmf: getDatamodel(), // defaults to false, uses /// comments from prisma schema as descriptions // for object types, relations and exposed fields. // descriptions can be omitted by setting description to false exposeDescriptions: boolean | { models: boolean, fields: boolean }, // use where clause from prismaRelatedConnection for totalCount (defaults to true) filterConnectionTotalCount: true, // warn when not using a query parameter correctly onUnusedQuery: process.env.NODE_ENV === 'production' ? null : 'warn', }, }); ``` -------------------------------- ### Install Errors Plugin Source: https://github.com/hayes/pothos/blob/main/packages/plugin-errors/README.md Install the Errors plugin using npm. ```bash npm install --save @pothos/plugin-errors ``` -------------------------------- ### GraphQL Query Example Source: https://github.com/hayes/pothos/blob/main/examples/open-telemetry/README.md A sample GraphQL query to be executed against the running Pothos server. It demonstrates fetching two 'hello' fields with different delays to observe tracing behavior. ```graphql { fastHello: hello(delay: 10) slowHello: hello(delay: 1000) } ``` -------------------------------- ### Install Directive Plugin Source: https://github.com/hayes/pothos/blob/main/website/content/docs/plugins/directives.mdx Install the Pothos Directive plugin using npm. ```bash npm install --save @pothos/plugin-directives ``` -------------------------------- ### Create a Basic GraphQL Server with Pothos Source: https://github.com/hayes/pothos/blob/main/website/content/docs/index.mdx This snippet demonstrates how to set up a simple GraphQL server using Pothos and GraphQL Yoga. It defines a basic 'hello' query that accepts an optional name argument. ```typescript import { createYoga } from 'graphql-yoga'; import { createServer } from 'node:http'; import SchemaBuilder from '@pothos/core'; const builder = new SchemaBuilder({}); builder.queryType({ fields: (t) => ({ hello: t.string({ args: { name: t.arg.string(), }, resolve: (parent, { name }) => `hello, ${name || 'World'}`, }), }), }); const yoga = createYoga({ schema: builder.toSchema(), }); const server = createServer(yoga); server.listen(3000, () => { console.log('Visit http://localhost:3000/graphql'); }); ``` -------------------------------- ### Setup Smart Subscriptions Plugin Source: https://github.com/hayes/pothos/blob/main/packages/plugin-smart-subscriptions/README.md Configure the Pothos SchemaBuilder with the SmartSubscriptionsPlugin and define subscription options. ```typescript import SchemaBuilder from '@pothos/core'; import SmartSubscriptionsPlugin from '@pothos/plugin-smart-subscriptions'; const builder = new SchemaBuilder({ plugins: [SmartSubscriptionsPlugin], smartSubscriptions: { debounceDelay: number | null; subscribe: ( name: string, context: Context, cb: (err: unknown, data?: unknown) => void, ) => Promise | void; unsubscribe: (name: string, context: Context) => Promise | void; }, }); ``` -------------------------------- ### Run Zipkin in Docker Source: https://github.com/hayes/pothos/blob/main/examples/open-telemetry/README.md Starts a Zipkin server instance using Docker. This is required for collecting and visualizing traces. ```bash docker run -d -p 9411:9411 openzipkin/zipkin ``` -------------------------------- ### Install Dataloader Plugin Source: https://github.com/hayes/pothos/blob/main/website/content/docs/plugins/dataloader.mdx Install the dataloader package and the Pothos dataloader plugin using npm. ```bash npm install --save dataloader @pothos/plugin-dataloader ``` -------------------------------- ### Install Sentry Tracing Dependencies Source: https://github.com/hayes/pothos/blob/main/packages/plugin-tracing/README.md Installs the necessary npm packages for Sentry tracing with Pothos. ```bash npm install --save @pothos/tracing-sentry @sentry/node ```