Skip to content

Instantly share code, notes, and snippets.

View wojciech-bilicki's full-sized avatar

Wojciech Bilicki wojciech-bilicki

  • Oke Software
  • Gdańsk
View GitHub Profile
@wojciech-bilicki
wojciech-bilicki / server.js
Created April 11, 2018 13:07
Adding connection to the DB
import express from 'express';
import {graphiqlExpress, graphqlExpress } from 'apollo-server-express';
import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import schema from './schema';
const server = express();
server.use('/graphiql', graphiqlExpress({
endpointURL: "/graphql"
@wojciech-bilicki
wojciech-bilicki / resolvers.js
Created April 11, 2018 12:31
Resolver with select
const resolvers = {
Query: {
authors: () => {
return authors
},
author: (root, args) => {
const age = args.age;
return authors.find(author => author.age === age);
}
}
const resolvers = {
Query: {
authors: () => {
return authors
},
author: (root, args) => {
}
}
}
const typeDefs = `
type Author {
age: Int
name: String,
Books: [String]
}
type Query {
authors: [Author]
const authors = [
{
name: 'JK Rowling',
age: 50,
Books: ["Harry Potter and the Goblet of Fire", "Harry Potter and the Prisoner of Azkaban"]
},
{
name: 'George RR Marting',
age: 70,
Books: ["GOT - Song of Ice and Fire", "GOT - A Dance with Dragons"]
const authors = [
{
name: 'JK Rowling',
age: 50
books: ["Harry Potter and the Goblet of Fire", "Harry Potter and the Prisoner of Azkaban"]
},
{
name: 'George RR Marting',
age: 70,
books: ["GOT - Song of Ice and Fire", "GOT - A Dance with Dragons"]
@wojciech-bilicki
wojciech-bilicki / server.js
Created April 11, 2018 10:45
server with schema
import express from 'express';
import {graphiqlExpress, graphqlExpress } from 'apollo-server-express';
import bodyParser from 'body-parser';
import schema from './schema';
const server = express();
server.use('/graphiql', graphiqlExpress({
endpointURL: "/graphql"
}))
@wojciech-bilicki
wojciech-bilicki / schema.js
Last active April 11, 2018 10:48
adding query type
import {makeExecutableSchema, addMockFunctionsToSchema} from 'graphql-tools';
const typeDefs = `
type Author {
age: Int
name: String,
Books: [String]
}
type Query {
@wojciech-bilicki
wojciech-bilicki / schema.js
Last active April 11, 2018 10:48
mock data
import {makeExecutableSchema, addMockFunctionsToSchema} from 'graphql-tools';
const typeDefs = `
type Author {
age: Int
name: String,
Books: [String]
}
`;
@wojciech-bilicki
wojciech-bilicki / schema.js
Created April 11, 2018 10:32
Author schema
import {makeExecutableSchema} from 'graphql-tools';
const typeDefs = `
type Author {
age: Int
name: String,
Books: [String]
}
`;