Last active
January 4, 2018 21:41
-
-
Save maticzav/753b69c66ca9f9be9c8a007909959a1b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// src/resolvers/index.ts | |
import { note } from './Query/note' | |
import { notes } from './Mutation/notes' | |
export const resolvers = { | |
Query: { | |
note, | |
}, | |
Mutation: { | |
...notes | |
} | |
} | |
// src/resolvers/Query/note.ts | |
import { Context, getUserId, AuthError } from '../../utils' | |
export const note = async (_, { id }, ctx: Context, info) => { | |
const userId = getUserId(ctx) | |
const hasPermission = await ctx.db.exists.Note({ | |
id, | |
owner: { id: userId } | |
}) | |
if (!hasPermission) { | |
throw new AuthError() | |
} | |
return await ctx.db.query.note({ where: { id } }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment