Skip to content

Commit

Permalink
Add simple way to modify built-in GraphQL query types
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAMathews committed Oct 27, 2016
1 parent 4c79370 commit 18b8b64
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
28 changes: 15 additions & 13 deletions lib/schema/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* @flow weak */
import _ from 'lodash'
import path from 'path'
import Promise from 'bluebird'
Expand All @@ -9,8 +10,9 @@ import {
import { siteDB } from '../utils/globals'
import markdownSchema from './markdown'
import siteSchema from './site-schema'
import apiRunnerNode from '../utils/api-runner-node'

const main = () => {
module.exports = async () => {
const config = siteDB().get(`config`)

return new Promise((resolve, reject) => {
Expand All @@ -23,21 +25,21 @@ const main = () => {
reject(error)
})
.then((types) => {
console.log(`types`, types)

const mergedTypes = _.merge(...types)
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: `RootQueryType`,
fields: {
...mergedTypes,
},
}),
})
apiRunnerNode(`modifyGraphQLFields`, { types: mergedTypes }, mergedTypes)
.then((modifiedTypes) => {
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: `RootQueryType`,
fields: () => ({
...modifiedTypes,
}),
}),
})

resolve(schema)
resolve(schema)
})
})
})
}

module.exports = main
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"front-matter": "^2.1.0",
"fs-extra": "^0.30.0",
"glob": "^7.1.0",
"graphql": "^0.7.0",
"graphql": "^0.7.2",
"graphql-relay": "^0.4.3",
"hapi": "^8.5.1",
"hapi-graphql": "^1.0.1",
Expand Down

0 comments on commit 18b8b64

Please sign in to comment.