From 5dde34eed8c936fdb195e2899579de164aaa0748 Mon Sep 17 00:00:00 2001 From: Rhys Evans Date: Mon, 7 Dec 2020 13:13:41 +0000 Subject: [PATCH] tidy up and make sure still works in build in particular, sort out webpack resolutions to work with .mjs --- Makefile | 3 -- compose-test.js | 7 ---- .../__tests__/graphql-defs.spec.js | 34 +++++++++---------- .../data-accessors/graphql-defs.js | 16 +++++---- webpack.config.js | 7 +++- 5 files changed, 32 insertions(+), 35 deletions(-) delete mode 100644 compose-test.js diff --git a/Makefile b/Makefile index 2e650e34a..e06d00c0f 100644 --- a/Makefile +++ b/Makefile @@ -154,6 +154,3 @@ prepublish: monorepo-publish: prepublish npx athloi version --concurrency 10 $(CIRCLE_TAG) npx athloi publish --concurrency 10 -- --access public - -ct: - TREECREEPER_SCHEMA_DIRECTORY=example-schema node compose-test.js diff --git a/compose-test.js b/compose-test.js deleted file mode 100644 index 5d7bb7789..000000000 --- a/compose-test.js +++ /dev/null @@ -1,7 +0,0 @@ -const schema = require('@financial-times/tc-schema-sdk'); - -void (async function () { - schema.init(); - await schema.ready(); - console.log(schema.getGraphqlDefs()); -})(); diff --git a/packages/tc-schema-sdk/data-accessors/__tests__/graphql-defs.spec.js b/packages/tc-schema-sdk/data-accessors/__tests__/graphql-defs.spec.js index 7800121aa..2b70d4460 100644 --- a/packages/tc-schema-sdk/data-accessors/__tests__/graphql-defs.spec.js +++ b/packages/tc-schema-sdk/data-accessors/__tests__/graphql-defs.spec.js @@ -93,7 +93,7 @@ describe('graphql def creation', () => { }, level: { type: 'TrafficLight', - description: "How good it is" + description: 'How good it is', }, hasBudget: { type: 'CostCentre', @@ -166,11 +166,11 @@ describe('graphql def creation', () => { enums: {}, stringPatterns, primitiveTypes: { - Word: { - graphql: 'String', - component: 'Text', + Word: { + graphql: 'String', + component: 'Text', + }, }, - }, }; const generated = [].concat(...graphqlFromRawData(schema)).join(''); // note the regex has a space, not a new line @@ -213,11 +213,11 @@ describe('graphql def creation', () => { enums: {}, stringPatterns, primitiveTypes: { - Word: { - graphql: 'String', - component: 'Text', + Word: { + graphql: 'String', + component: 'Text', + }, }, - }, }; const generated = [].concat(...graphqlFromRawData(schema)).join(''); // note the regex has a space, not a new line @@ -249,11 +249,11 @@ describe('graphql def creation', () => { graphql: 'String', component: 'Text', }, - Word: { - graphql: 'String', - component: 'Text', + Word: { + graphql: 'String', + component: 'Text', + }, }, - }, }; const generated = [].concat(...graphqlFromRawData(schema)).join(''); @@ -281,11 +281,11 @@ line with enums: {}, stringPatterns, primitiveTypes: { - Word: { - graphql: 'String', - component: 'Text', + Word: { + graphql: 'String', + component: 'Text', + }, }, - }, }; const generated = [].concat(...graphqlFromRawData(schema)).join(''); expect(generated).toMatch( diff --git a/packages/tc-schema-sdk/data-accessors/graphql-defs.js b/packages/tc-schema-sdk/data-accessors/graphql-defs.js index d243346bd..18b0103ec 100644 --- a/packages/tc-schema-sdk/data-accessors/graphql-defs.js +++ b/packages/tc-schema-sdk/data-accessors/graphql-defs.js @@ -31,7 +31,7 @@ const getRelationshipTypeName = ({ ); }; -const composeStaticDefinitions = composer => { +const addStaticDefinitions = composer => { composer.addDirective( new GraphQLDirective({ name: 'deprecated', @@ -53,7 +53,7 @@ const composeStaticDefinitions = composer => { composer.createScalarTC('Time'); }; -const composeEnumDefinitions = (composer, sdk) => { +const addEnumDefinitions = (composer, sdk) => { Object.entries(sdk.getEnums({ withMeta: true })).map( ([name, { description: enumDescription, options }]) => { const values = {}; @@ -110,7 +110,6 @@ const composeObjectProperties = ({ typeName, properties, sdk, composer }) => { extensions: { directives: getDirectives(def), }, - // TODO - is pagination needed to be set explicitly args: getArgs(def), }); @@ -143,7 +142,6 @@ as well as on the records themselves. Use '${fieldName}' instead if you do not n sdk.getRelationshipType(typeName, fieldName), ), ), - // TODO - is pagination needed to be set explicitly args: getArgs(def), }); } @@ -173,7 +171,10 @@ const addTypeDefinition = (composer, sdk) => ({ ...Object.fromEntries( Object.entries(properties) .filter(([, def]) => !def.relationship && !def.cypher) - .map(([name, { type }]) => [name, getGraphqlType(sdk)(type)]), + .map(([name, { type }]) => [ + name, + getGraphqlType(sdk)(type), + ]), ), }, }); @@ -218,8 +219,8 @@ const addRelationshipTypeDefinition = (composer, sdk) => ({ const compose = sdk => { const composer = new SchemaComposer(); - composeStaticDefinitions(composer); - composeEnumDefinitions(composer, sdk); + addStaticDefinitions(composer); + addEnumDefinitions(composer, sdk); sdk.getTypes({ includeMetaFields: true, }).forEach(addTypeDefinition(composer, sdk)); @@ -234,6 +235,7 @@ const compose = sdk => { module.exports = { accessor() { + // still return an array for backwards compatibility... for now return [compose(this).toSDL()]; }, }; diff --git a/webpack.config.js b/webpack.config.js index a29cd488e..0dbbd0d3f 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -7,7 +7,7 @@ const filenameTemplate = '[name]'; module.exports = { entry: ['./demo/cms/browser/main.js'], resolve: { - extensions: ['.js', '.jsx', '.css'], + extensions: ['.mjs', '.js', '.jsx', '.css'], }, output: { path: path.resolve(__dirname, 'dist/browser'), @@ -16,6 +16,11 @@ module.exports = { stats: 'minimal', module: { rules: [ + { + test: /\.mjs$/, + include: /node_modules/, + type: 'javascript/auto', + }, { test: /\.jsx?$/, exclude: /node_modules/,