sendou.ink/schemas/link.js
2019-06-19 20:17:47 +03:00

38 lines
658 B
JavaScript

const { UserInputError, gql } = require('apollo-server-express')
const Link = require('../models/link')
const typeDef = gql`
extend type Query {
links: [Link!]!
}
enum LinkType {
DISCORD
GUIDE
MISC
}
type Link {
title: String!
url: String!
description: String!
type: LinkType!
}
`
const resolvers = {
Query: {
links: (root, args) => {
return Link
.find({})
.sort({ "title": "asc" })
.catch(e => {
throw new UserInputError(e.message, {
invalidArgs: args,
})
})
}
}
}
module.exports = {
Link: typeDef,
linkResolvers: resolvers
}