Skip to content

Instantly share code, notes, and snippets.

@mhaagens
Last active July 2, 2018 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhaagens/b9ba0ee79201a872e27012b0c39f0621 to your computer and use it in GitHub Desktop.
Save mhaagens/b9ba0ee79201a872e27012b0c39f0621 to your computer and use it in GitHub Desktop.
Authentication and authorization using GraphQL Schema Directives: src/models/post.js
const { gql } = require("apollo-server");
const mockPosts = [
{ id: 1, title: "Helvetica and Times New Roman walk into a bar. Get out of here! shouts the bartender. We don't serve your type!", ownerId: 1 },
{ id: 2, title: "Why do we tell actors to break a leg? Because every play has a cast.", ownerId: 2 },
{ id: 3, title: "Did you hear about the mathematician who’s afraid of negative numbers? He'll stop at nothing to avoid them.", ownerId: 1 }
];
module.exports.postDefs = gql`
extend type Query {
posts: [Post] @requireAuth
}
type Post {
id: Int
title: String
}
`;
module.exports.postResolvers = {
Query: {
posts: () => mockPosts
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment