Created
November 15, 2022 06:11
-
-
Save acro5piano/3d6eec7ba621497ebaa225a9e1028fe0 to your computer and use it in GitHub Desktop.
new graphql framework idea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { type, t, getExecutableSchema } = '../framework' | |
interface('Node', { | |
id: t('ID!'), | |
}) | |
type('User', implements('Node'), { | |
height: t('Int!'), | |
posts: t('[Post!]!').allowWhere().allowOrder(), | |
}) | |
type('Post', implements('Node'), { | |
title: t('String!'), | |
user: t('User!'), | |
}) | |
type('Query', { | |
users: t('[User!]!') | |
.args({ page: t.number().defaultTo(0) }) | |
.resolver(({ args, ctx: { orm } }) => | |
orm.User.limit(10).offset(args.page * 10), | |
), | |
usersWithoutPost: t('[User!]!') | |
.invisible() | |
.resolver(({ ctx: { orm } }) => orm.User.limit(10).offset(args.page * 10)), | |
viewer: t('User').resolver(auth.getViewer), | |
}) | |
type('Mutation', { | |
updateUser: t('User!') | |
.args({ input: t('UserInput!') }) | |
.resolver(({ args, ctx: { uid, orm } }) => | |
orm.User.update(args).where({ id: uid }).returning('*').returnFirst(), | |
), | |
deleteUser: t('Boolean!') | |
.useTransaction() | |
.resolver(async ({ ctx: { uid, firebaseUid, orm } }) => { | |
await orm.User.delete().where({ id: uid }).returning('*').returnFirst() | |
await firebase.auth().deleteUser(firebaseUid) | |
}), | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment