Migrating from Prisma+Nexus to Prisma+Pothos #511
-
Hey, thanks for all your work on pothos! Unable to change context shapeAll Query entrypoints require an Auth token, so all export const builder = new SchemaBuilder<{
Context: IContext;
AuthScopes: { loggedIn: boolean }
AuthContexts: { loggedIn: IAuthContext }
...
}>({
plugins: [ScopeAuth, PrismaPlugin],
...
scopeAuthOptions: {
runScopesOnType: true,
},
authScopes: (context) => ({
loggedIn: !!context.user || !!context.hub
})
}) along with copy pasting this across all my prismaObjects builder.prismaObject('Hub', {
authScopes: {loggedIn: true},
runScopesOnType: true,
fields: (t) => ({
...
}) But I can't get the context to change from Exposing IDJust a question about Viewer field (non-prisma models)One of my builder.queryType({
fields: (t) => ({
....
viewer: t.field({
type: Viewer,
resolve(_root, _args, { user }) {
if (!user) throw new AuthenticationError("User does not have permission")
return ({}) // <--------------is this correct?
}
}),
})
})
export class Viewer {
constructor(
user: User,
hubs: Hub[],
networks: Network[],
latestSensorVersion: string,
) {}
}
builder.objectType(Viewer, {
fields: (t) => ({
user: t.prismaField({
type: "User",
resolve: (query, _root, _args, { user }) => {
return user
},
}),
...
})
}) but I get this error for the viewer object
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 12 replies
-
If all entrypoints guarantee a user, you can use just make your auth context the default context: export const builder = new SchemaBuilder<{
Context: IAuthContext;
AuthScopes: { loggedIn: boolean }
}>({...}) The plugin isn't currently changing the context type automatically for fields of a type that have defined scopes. To change the context based on scopes you need to use either the also, just a note: if you have
No, this will be exoised as in
When you use a class for an object type like: |
Beta Was this translation helpful? Give feedback.
If all entrypoints guarantee a user, you can use just make your auth context the default context:
The plugin isn't currently changing the context type automatically for fields of a type that have defined scopes. To change the context based on scopes you need to use either the
t.authField
method, or thet.w…