Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie committed Mar 3, 2020
1 parent 949f2f6 commit cc90a8e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
1 change: 0 additions & 1 deletion packages/app-admin-ui/tests/server/AdminUI.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ jest.doMock('html-webpack-plugin', () => {
const { AdminUIApp } = require('../../');

const keystone = {
getAdminSchema: jest.fn(),
getAdminMeta: jest.fn(),
};
const adminPath = 'admin_path';
Expand Down
3 changes: 2 additions & 1 deletion packages/app-graphql/lib/apolloServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ function createApolloServer(keystone, apolloConfig, schemaName, dev) {
const server = new ApolloServer({
maxFileSize: 200 * 1024 * 1024,
maxFiles: 5,
...keystone.getAdminSchema({ schemaName }),
typeDefs: keystone.getTypeDefs({ schemaName }),
resolvers: keystone.getResolvers({ schemaName }),
context: ({ req }) => ({
...keystone.getGraphQlContext({ schemaName, req }),
req,
Expand Down
44 changes: 18 additions & 26 deletions packages/keystone/lib/Keystone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,13 @@ module.exports = class Keystone {
return { lists, name: this.name };
}

// It's not Keystone core's responsibility to create an executable schema, but
// once one is, Keystone wants to be able to expose the ability to query that
// schema, so this function enables other modules to register that function.
registerSchema(schemaName, schema) {
this._schemas[schemaName] = schema;
}

getTypeDefs({ schemaName }) {
const queries = unique(flatten(this._providers.map(p => p.getQueries({ schemaName }))));
const mutations = unique(flatten(this._providers.map(p => p.getMutations({ schemaName }))));
Expand All @@ -437,38 +444,23 @@ module.exports = class Keystone {
.map(s => print(gql(s)));
}

// It's not Keystone core's responsibility to create an executable schema, but
// once one is, Keystone wants to be able to expose the ability to query that
// schema, so this function enables other modules to register that function.
registerSchema(schemaName, schema) {
this._schemas[schemaName] = schema;
}

getAdminSchema({ schemaName }) {
getResolvers({ schemaName }) {
// Like the `typeDefs`, we want to dedupe the resolvers. We rely on the
// semantics of the JS spread operator here (duplicate keys are overridden
// - first one wins)
// TODO: Document this order of precendence, because it's not obvious, and
// there's no errors thrown
// TODO: console.warn when duplicate keys are detected?
return {
typeDefs: this.getTypeDefs({ schemaName }).map(
typeDef =>
gql`
${typeDef}
`
),
resolvers: filterValues(
{
// Order of spreading is important here - we don't want user-defined types
// to accidentally override important things like `Query`.
...objMerge(this._providers.map(p => p.getTypeResolvers({ schemaName }))),
Query: objMerge(this._providers.map(p => p.getQueryResolvers({ schemaName }))),
Mutation: objMerge(this._providers.map(p => p.getMutationResolvers({ schemaName }))),
},
o => Object.entries(o).length > 0
),
};
return filterValues(
{
// Order of spreading is important here - we don't want user-defined types
// to accidentally override important things like `Query`.
...objMerge(this._providers.map(p => p.getTypeResolvers({ schemaName }))),
Query: objMerge(this._providers.map(p => p.getQueryResolvers({ schemaName }))),
Mutation: objMerge(this._providers.map(p => p.getMutationResolvers({ schemaName }))),
},
o => Object.entries(o).length > 0
);
}

dumpSchema(file, schemaName) {
Expand Down

0 comments on commit cc90a8e

Please sign in to comment.