Skip to content

Instantly share code, notes, and snippets.

@maticzav
Last active January 4, 2018 21:41
Show Gist options
  • Save maticzav/753b69c66ca9f9be9c8a007909959a1b to your computer and use it in GitHub Desktop.
Save maticzav/753b69c66ca9f9be9c8a007909959a1b to your computer and use it in GitHub Desktop.
// 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