KyleG
07/07/2018, 9:53 PMKyleG
07/07/2018, 9:53 PMUser
with the typical stuff like id: ID!
and email: String!
, and type: Int!
.
In order to prevent emails leaking out to other users, I removed the email
from the app schema's type `User`:
type User {
id: ID!
type: Int!
}
I have defined a second type PrivateUser
that has the `email`:
type PrivateUser {
id: ID!
email: String!
type: Int!
}
And I have a type AuthPayload
to deliver my JWT along with any PrivateUser
data I might want to use:
type AuthPayload {
token: String!
user: PrivateUser!
}
When I try to use Fragments this is what happens...KyleG
07/07/2018, 9:56 PMPrivateUser
type.
https://puu.sh/ASzxt/303ecdd40c.png▾
KyleG
07/07/2018, 10:00 PMtype AuthPayload {
token: String!
user: User!
}
And adjust my fragment to assume it's type User
(ignore the Playground error underlining, it still thinks user is PrivateUser
)
https://puu.sh/ASzDC/900419eb19.png▾
KyleG
07/07/2018, 10:12 PMasync login(parent, args, ctx) {
const user = await ctx.db.query.user({ where: { email: args.email } });
if (!user) {
throw new Error(`No such user found for email: ${args.email}`);
}
const valid = await bcrypt.compare(args.password, user.password);
if (!valid) {
throw new Error("Invalid password");
}
return {
token: jwt.sign({
id: user.id,
type: user.type,
status: user.status,
flags: user.flags,
}, process.env.APP_SECRET),
user,
};
},
My thought is: Is there something wrong with the variable user
in that function? I can confirm that without info
in ctx.db.query.user()
the contents of the user
object contains EVERYTHING that the login mutation claims to be missing in the first screenshot.KyleG
07/07/2018, 10:50 PMAuthPayload
type, finally revealing to me why the GraphQL boilerplate has this file in it: https://github.com/graphql-boilerplates/node-graphql-server/blob/master/advanced/src/resolvers/AuthPayload.js )KyleG
07/07/2018, 10:56 PMPrivateUser
does not match the internal query's type name User
?KyleG
07/07/2018, 11:58 PMprisma-binding
bug? Sorry that I don't know what project to blame this bug(?) on, as a guy who just jumped in on the 2nd floor with boilerplates there are so many modules involved that I personally can't keep them straight. 😅 I'll write an issue for it.checkmatez
07/10/2018, 11:51 AMPrivateUser
does not match the internal query's type name User
- I think, this is exactly what is happening. Info
contains AST for your app schema, while Prisma expects AST (or selection set) for Prisma schema. You need to convert between schemas manually using visit
from 'graphql' package. Here is forum post for inspiration: https://www.prisma.io/forum/t/how-to-handle-info-in-an-app-schema-with-additional-datatypes-than-db-schema/3800/7
I'm also waiting for blog post from Prisma team on a schema transforms topic 🙂nilan
07/14/2018, 11:16 AMnilan
07/14/2018, 11:16 AM