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
| // at the top with imports: | |
| import Mongoose from 'mongoose'; | |
| // somewhere in the middle: | |
| const mongo = Mongoose.connect('mongodb://localhost/views'); | |
| const ViewSchema = Mongoose.Schema({ | |
| postId: Number, | |
| views: Number, | |
| }); |
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
| import { Author } from './connectors'; | |
| const resolvers = { | |
| Query: { | |
| author(_, args) { | |
| return Author.find({ where: args }); | |
| }, | |
| }, | |
| Author: { | |
| posts(author) { |
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
| import Sequelize from 'sequelize'; | |
| import casual from 'casual'; | |
| import _ from 'lodash'; | |
| const db = new Sequelize('blog', null, null, { | |
| dialect: 'sqlite', | |
| storage: './blog.sqlite', | |
| }); | |
| const AuthorModel = db.define('author', { |
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
| const resolvers = { | |
| Query: { | |
| author(root, args){ | |
| return { id: 1, firstName: 'Hello', lastName: 'World' }; | |
| }, | |
| }, | |
| Author: { | |
| posts(author){ | |
| return [ | |
| { id: 1, title: 'A post', text: 'Some text', views: 2}, |
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
| import casual from 'casual'; | |
| const mocks = { | |
| String: () => 'It works!', | |
| Query: () => ({ | |
| author: (root, args) => { | |
| return { firstName: args.firstName, lastName: args.lastName }; | |
| }, | |
| }), | |
| Author: () => ({ firstName: () => casual.first_name, lastName: () => casual.last_name }), |
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
| import { makeExecutableSchema } from 'graphql-tools'; | |
| const typeDefs = ` | |
| type Author { | |
| id: Int | |
| firstName: String | |
| lastName: String | |
| posts: [Post] | |
| } | |
| type Post { |
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
| import { | |
| makeExecutableSchema, | |
| addMockFunctionsToSchema, | |
| } from 'graphql-tools'; | |
| import mocks from './mocks' | |
| const typeDefs = ` | |
| type Query { | |
| testString: String | |
| } |
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
| import { mockServer, MockList } from 'graphql-tools'; | |
| import casual from 'casual-browserify'; | |
| // The GraphQL schema. Described in more detail here: | |
| // https://medium.com/apollo-stack/the-apollo-server-bc68762e93b | |
| const schema = ` | |
| type User { | |
| id: ID! | |
| name: String |
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
| // customize mocking per type (i.e. Integer, Float, String) | |
| mockServer(schema, { | |
| Int: () => 6, | |
| Float: () => 22.1, | |
| String: () => 'Hello', | |
| }); | |
| // customize mocking per field in the schema (i.e. for Person.name and Person.age) | |
| mockServer(schema, { |