-
I want to try to change some context typings based on the auth scoped passed to a field. For example: type SchemaBuilderConfig = {
Context: {
userAgent: string;
user: User | null;
};
AuthScopes: {
isLoggedIn: boolean;
isAdmin: boolean;
};
}
export const schemaBuilder = new SchemaBuilder<SchemaBuilderConfig>({
plugins: [ScopeAuthPlugin],
authScopes: async context => ({
isLoggedIn: !!context.user,
isAdmin: !!context.user?.isAdmin
}),
scopeAuthOptions: {...}
});
schemaBuilder.queryType({
fields: t => ({
hello: t.string({
authScopes: {
isLoggedIn: true
},
resolve: (_root, _args, context) => {
// context.user type to be User since isLoggedIn is required
return 'Hello world!';
}
})
})
}); For while I'm using the non-null assertion operator. |
Beta Was this translation helpful? Give feedback.
Answered by
hayes
Mar 19, 2022
Replies: 1 comment 2 replies
-
Seems like something got dropped from the docs Basically, you can provide custom contexts for your scopes and use auth field method to get a custom context |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
willianhf
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Seems like something got dropped from the docs
pothos/packages/plugin-scope-auth/tests/example/schema/index.ts
Line 5 in 7dd293d
pothos/packages/plugin-scope-auth/tests/example/builder.ts
Line 20 in 7dd293d
Basically, you can provide custom contexts for your scopes and use auth field method to get a custom context