-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement/issue 270 greenwood configuration as data (#296)
* Rfc/issue 115 build time data access (#269) * graphql server working * apollo client connect to apollo server * connected header example using lit apollo * todo * todos * query and client + server refactor * schema refactoring * clean up console logging * alias all @greenwood/cli/data module imports * avoid paramater destructuring * graphql example in the header * multiple schemas * internal data sources documentation * shelf refactor and children query integration * refactor out ApolloQuery * ability to intercept client.query calls * basic semi-working implementation * remove extra config from server context * have puppeteer wait for graphql requests before returning content * fix and add test cases for apollo * merged resolvers not actually working * multiple queries support * everything working * todos * TODO tracking * fix fallback apollo client fetch handling * full test suite * cache json test cases * stablize test due to inconsistent data results ordering * clean up deps * todo cleanup * remove forced client call in SSG mode for client * represent graph through the schema * updated data docs * typos and grammer * typos and community link fixes * hello and graph queries working together * config def and resolvers * use real config data * flesh out config schema and query * remove theme file from config * delete hello query example * config unit tests * rename mock graph * formatting * documentation
- Loading branch information
1 parent
8d1529a
commit ad9515b
Showing
15 changed files
with
271 additions
and
64 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
query { | ||
config { | ||
devServer { | ||
port, | ||
host | ||
}, | ||
meta { | ||
name, | ||
rel, | ||
content, | ||
property, | ||
value | ||
}, | ||
publicPath, | ||
title, | ||
workspace | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const { gql } = require('apollo-server'); | ||
|
||
const getConfiguration = async (root, query, context) => { | ||
return context.config; | ||
}; | ||
|
||
// https://www.greenwoodjs.io/docs/configuration | ||
const configTypeDefs = gql` | ||
type DevServer { | ||
port: Int, | ||
host: String | ||
} | ||
type Meta { | ||
name: String, | ||
value: String, | ||
content: String, | ||
rel: String, | ||
property: String | ||
} | ||
type Config { | ||
devServer: DevServer, | ||
meta: [Meta], | ||
publicPath: String, | ||
title: String, | ||
workspace: String | ||
} | ||
extend type Query { | ||
config: Config | ||
} | ||
`; | ||
|
||
const configResolvers = { | ||
Query: { | ||
config: getConfiguration | ||
} | ||
}; | ||
|
||
module.exports = { | ||
configTypeDefs, | ||
configResolvers | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,22 @@ | ||
// TODO merging resolvers not actually working, resolve as part of #21 or #270 | ||
const { makeExecutableSchema } = require('apollo-server-express'); | ||
const { helloTypeDefs, helloResolvers } = require('./hello'); | ||
const { configTypeDefs, configResolvers } = require('./config'); | ||
const { graphTypeDefs, graphResolvers } = require('./graph'); | ||
|
||
const mergedResolvers = Object.assign({}, { | ||
Query: { | ||
...configResolvers.Query, | ||
...graphResolvers.Query | ||
} | ||
}); | ||
|
||
const schema = makeExecutableSchema({ | ||
typeDefs: [ | ||
graphTypeDefs, | ||
helloTypeDefs | ||
configTypeDefs, | ||
graphTypeDefs | ||
], | ||
resolvers: Object.assign({}, | ||
graphResolvers, | ||
helloResolvers | ||
) | ||
resolvers: [ | ||
mergedResolvers | ||
] | ||
}); | ||
|
||
module.exports = schema; |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const MOCK_CONFIG = { | ||
config: { | ||
devServer: { | ||
port: 1984, | ||
host: 'localhost' | ||
}, | ||
meta: [ | ||
{ name: 'twitter:site', content: '@PrjEvergreen' }, | ||
{ rel: 'icon', href: '/assets/favicon.ico' } | ||
], | ||
publicPath: '/some-dir', | ||
title: 'My App', | ||
workspace: 'src' | ||
} | ||
}; | ||
|
||
module.exports = MOCK_CONFIG; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
const expect = require('chai').expect; | ||
const MOCK_CONFIG = require('../mocks/config'); | ||
const { configResolvers } = require('../../../../src/data/schema/config'); | ||
|
||
describe('Unit Test: Data', function() { | ||
|
||
describe('Schema', function() { | ||
|
||
describe('Config', function() { | ||
let config = {}; | ||
|
||
before(async function() { | ||
config = await configResolvers.Query.config(undefined, {}, MOCK_CONFIG); | ||
}); | ||
|
||
describe('Dev Server', function() { | ||
const { devServer } = MOCK_CONFIG.config; | ||
|
||
it('should have the expected devServer.port', function() { | ||
expect(config.devServer.port).to.equal(devServer.port); | ||
}); | ||
|
||
it('should have the expected devServer.host', function() { | ||
expect(config.devServer.host).to.equal(devServer.host); | ||
}); | ||
}); | ||
|
||
describe('Meta', function() { | ||
const { meta } = MOCK_CONFIG.config; | ||
|
||
it('should have the expected name meta in the first indexx', function() { | ||
const nameMeta = config.meta[0]; | ||
|
||
expect(nameMeta.name).to.equal(meta[0].name); | ||
}); | ||
|
||
it('should have the expected devServer.host', function() { | ||
const nameMeta = config.meta[0]; | ||
|
||
expect(nameMeta.content).to.equal(meta[0].content); | ||
}); | ||
|
||
it('should have the expected rel meta in the second index', function() { | ||
const relMeta = config.meta[1]; | ||
|
||
expect(relMeta.rel).to.equal(meta[1].rel); | ||
}); | ||
|
||
it('should have the expected devServer.host', function() { | ||
const relMeta = config.meta[1]; | ||
|
||
expect(relMeta.content).to.equal(meta[1].content); | ||
}); | ||
}); | ||
|
||
describe('Public Path', function() { | ||
const { publicPath } = MOCK_CONFIG.config; | ||
|
||
it('should have the expected publicPath', function() { | ||
expect(publicPath).to.equal(config.publicPath); | ||
}); | ||
}); | ||
|
||
describe('Title', function() { | ||
const { title } = MOCK_CONFIG.config; | ||
|
||
it('should have the expected title', function() { | ||
expect(title).to.equal(config.title); | ||
}); | ||
}); | ||
|
||
describe('Workspace', function() { | ||
const { workspace } = MOCK_CONFIG.config; | ||
|
||
it('should have the expected title', function() { | ||
expect(workspace).to.equal(config.workspace); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
}); |
This file contains 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
This file contains 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
Oops, something went wrong.