Creating connections in Pothos coming from Nexus #1022
-
|
Hello. I can't seem to figure out how to convert connection plugin (relay plugin) from Nexus to Pothos based on this setup: https://pothos-graphql.dev/docs/plugins/relay#setup So in Nexus, you can create multiple relay plugins when creating a schema like so: export const schema = makeSchema({
features: {
abstractTypeStrategies: {
isTypeOf: true,
},
abstractTypeRuntimeChecks: true,
},
types: schemaTypes,
plugins: [
connectionPlugin({}),
connectionPlugin({
nexusFieldName: 'basicConnectionField',
disableBackwardPagination: true,
extendConnection: {
meta: {
requireResolver: false,
type: 'SearchMeta',
},
},
}),
connectionPlugin({
typePrefix: 'Complex',
nexusFieldName: 'complexConnectionField',
extendConnection: {
cacheID: {
type: 'String',
},
totalCount: { type: 'Int', description: 'The total count of results.' },
pageCursors: { type: 'PageCursors', description: 'The page cursors for pagination of the results.' },
},
additionalArgs: {
cacheID: nullable(
stringArg({
description:
'Reuse IDs it has saved for filter.',
})
),
},
}),
],
outputs: {
schema: path.join(__dirname, 'generated', 'schema.graphql'),
typegen: path.join(__dirname, 'generated', 'nexus.ts'),
},
contextType: {
export: 'ContextType',
module: 'context-absolute-path-here',
},
});and can be used this way: export const ThingsQuery = queryField(t => {
t.complexConnectionField('things', {
type: 'Thing',
...
});
});Is there a guide with regards to Nexus to Pothos conversion or maybe if someone experience moving away from Nexus to Pothos? Thanks for the help. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
|
I don't know of anything that covers migrations from Nexus in depth like this. Unfortunately Pothos doesn't have support for multiple instances of a plugin like you are describing, but there is an example here for handling windowed pagination: https://github.com/hayes/pothos/tree/main/examples/relay-windowed-pagination/src |
Beta Was this translation helpful? Give feedback.
-
|
@hayes I finally got it. Just want to say thanks for all your support and samples that has greatly helped me figure out how to go about nexus and pothos connection fields. Hopefully that's the last issue I'd encounter regarding relay during this migration. To prevent Nexus PageInfo and Pothos PageInfo from "duplicate typename" issue, I deleted the PageInfo before passing it in pothos schema builder like so // Remove the PageInfo type to prevent Duplicate typename (Nexus has its own relay plugin which conflicts with Pothos relay plugin)
const modifiedSchema = schema;
const schemaTypes = modifiedSchema.getTypeMap();
if (schemaTypes['PageInfo']) {
delete schemaTypes['PageInfo'];
}
export const schemaViaPothosBuilder = new SchemaBuilder<{
Context: ContextType;
Scalars: {
PlainText: {
Input: string;
Output: string;
};
RichText: {
Input: string;
Output: string;
};
};
Connection: {
totalCount: number;
filterCacheID: string;
pageCursors: {
first: PageCursor;
last: PageCursor;
neighbours: PageCursor[];
};
};
}>({
plugins: [AddGraphQLPlugin, RelayPlugin],
relay: {},
add: {
schema: modifiedSchema,
},
notStrict: 'Pothos may not work correctly when strict mode is not enabled in tsconfig.json',
}); |
Beta Was this translation helpful? Give feedback.

@hayes I finally got it. Just want to say thanks for all your support and samples that has greatly helped me figure out how to go about nexus and pothos connection fields. Hopefully that's the last issue I'd encounter regarding relay during this migration.
To prevent Nexus PageInfo and Pothos PageInfo from "duplicate typename" issue, I deleted the PageInfo before passing it in pothos schema builder like so