Skip to content

Commit

Permalink
fixed fimal tests affected by apollo 2 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
wheresrhys committed Sep 2, 2019
1 parent b2de28c commit a864c9c
Show file tree
Hide file tree
Showing 6 changed files with 1,412 additions and 1,789 deletions.
7 changes: 6 additions & 1 deletion __mocks__/node-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ const fetchMock = require('fetch-mock').sandbox();

Object.assign(fetchMock.config, nodeFetch, {
fetch: nodeFetch,

fallbackToNetwork: 'always',
});
module.exports = fetchMock;
module.exports = Object.assign(fetchMock, {
Request: nodeFetch.Request,
Response: nodeFetch.Response,
Headers: nodeFetch.Headers,
});
4 changes: 3 additions & 1 deletion api/server/health/schema-version.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { checkSchemaConsistency } = require('../routes/graphql/api');
const {
checkSchemaConsistency,
} = require('../routes/graphql/lib/get-augmented-schema');
const healthcheck = require('./healthcheck');

const schemaVersionCheck = () => {
Expand Down
37 changes: 18 additions & 19 deletions api/server/routes/graphql/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,28 @@ const apollo = new ApolloServer({
});

module.exports = router => {
router.use(timeout(TIMEOUT));
router.use((req, res, next) => {
if (req.get('client-id')) {
return clientId(req, res, next);
}
next();
});
router.use(security.requireApiKeyOrS3o);
router.use(maintenance.disableReads);
router.use([
timeout(TIMEOUT),
(req, res, next) => {
if (req.get('client-id')) {
return clientId(req, res, next);
}
next();
},
security.requireApiKeyOrS3o,
maintenance.disableReads,
bodyParser.json({ limit: '8mb' }),
bodyParser.urlencoded({ limit: '8mb', extended: true }),

(req, res, next) => {
res.nextMetricsName = 'graphql';
setContext({ endpoint: 'graphql', method: req.method });
logger.info({
event: 'GRAPHQL_REQUEST',
body: req.body,
});
next();
},
]);
router.use((req, res, next) => {
res.nextMetricsName = 'graphql';
setContext({ endpoint: 'graphql', method: req.method });
logger.info({
event: 'GRAPHQL_REQUEST',
body: req.body,
});
next();
});
apollo.applyMiddleware({ app: router, path: '/' });

return router;
Expand Down
10 changes: 5 additions & 5 deletions api/server/routes/graphql/graphiql.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ module.exports = router => {
settings: {
'request.credentials': 'same-origin',
},
tabs: {
endpoint: '/graphiql/example',
query: DEFAULT_QUERY,
name: 'Example',
},
// tabs: {
// endpoint: '/graphiql/example',
// query: DEFAULT_QUERY,
// name: 'Example',
// },
}),
);
return router;
Expand Down
198 changes: 114 additions & 84 deletions api/server/routes/graphql/lib/get-augmented-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,123 +5,153 @@ const EventEmitter = require('events');
const {
getGraphqlDefs,
onChange,
rawData,
} = require('../../../../../packages/schema-sdk');

const { sendSchemaToS3 } = require('../../../../../packages/schema-publisher');

let schemaVersionIsConsistent = true;

const schemaEmitter = new EventEmitter();

let defs;

const getAugmentedSchema = () => {
const typeDefs = defs || getGraphqlDefs();
// this should throw meaningfully if the defs are invalid;
parse(typeDefs.join('\n'));
const schema = makeAugmentedSchema({
typeDefs: [
`
try {
const typeDefs = defs || getGraphqlDefs();
// this should throw meaningfully if the defs are invalid;
parse(typeDefs.join('\n'));
const schema = makeAugmentedSchema({
typeDefs: [
`
directive @deprecated(
reason: String = "No longer supported"
) on FIELD_DEFINITION | ENUM_VALUE | ARGUMENT_DEFINITION`,
]
.concat(typeDefs)
.join('\n'),
logger: {
log(message) {
logger.error(`GraphQL Schema: ${message}`, {
event: 'GRAPHQL_SCHEMA_ERROR',
});
]
.concat(typeDefs)
.join('\n'),
logger: {
log(message) {
logger.error(`GraphQL Schema: ${message}`, {
event: 'GRAPHQL_SCHEMA_ERROR',
});
},
},
},
config: { query: true, mutation: false, debug: true },
});
return schema;
config: { query: true, mutation: false, debug: true },
});
schemaVersionIsConsistent = true;
logger.info({ event: 'GRAPHQL_SCHEMA_UPDATED' });

if (process.env.NODE_ENV === 'production') {
sendSchemaToS3('api', rawData.getAll())
.then(() => {
logger.info({ event: 'GRAPHQL_SCHEMA_SENT_TO_S3' });
})
.catch(error => {
logger.error({
event: 'SENDING_SCHEMA_TO_S3_FAILED',
error,
});
});
}
return schema;
} catch (error) {
schemaVersionIsConsistent = false;
logger.error(
{ event: 'GRAPHQL_SCHEMA_UPDATE_FAILED', error },
'Graphql schema update failed',
);
}
};

onChange(() => schemaEmitter.emit('schemaUpdate', getAugmentedSchema()));

module.exports = { schemaEmitter, getAugmentedSchema };

setTimeout(() => {
defs = [
`
scalar DateTime
scalar Date
scalar Time
"""
Some business function carried out at FT e.g. ability to publish the news, ability to pay staff...
"""
type BusinessCapability {
module.exports = {
schemaEmitter,
getAugmentedSchema,
checkSchemaConsistency: () => schemaVersionIsConsistent,
};

"""
The unique identification code for the capability. When creating a new capability,
choose a lower case, hyphenated string similar to the name people call the capability.
// setTimeout(() => {
// defs = [
// `
// scalar DateTime
// scalar Date
// scalar Time
// """
// Some business function carried out at FT e.g. ability to publish the news, ability to pay staff...

"""
code: String
"""
The name generally used to refer to the capability.
// """
// type BusinessCapability {

"""
namette: String
// """
// The unique identification code for the capability. When creating a new capability,
// choose a lower case, hyphenated string similar to the name people call the capability.

},
// """
// code: String
// """
// The name generally used to refer to the capability.

type Query {
// """
// namette: String

// },

"""
Some business function carried out at FT e.g. ability to publish the news, ability to pay staff...
// type Query {

"""
BusinessCapability(
// """
// Some business function carried out at FT e.g. ability to publish the news, ability to pay staff...

// """
// BusinessCapability(

"""
The unique identification code for the capability. When creating a new capability,
choose a lower case, hyphenated string similar to the name people call the capability.
// """
// The unique identification code for the capability. When creating a new capability,
// choose a lower case, hyphenated string similar to the name people call the capability.

"""
code: String
"""
The name generally used to refer to the capability.
// """
// code: String
// """
// The name generally used to refer to the capability.

"""
namette: String
): BusinessCapability
// """
// namette: String
// ): BusinessCapability

"""
Some business function carried out at FT e.g. ability to publish the news, ability to pay staff...
// """
// Some business function carried out at FT e.g. ability to publish the news, ability to pay staff...

"""
BusinessCapabilities(
// """
// BusinessCapabilities(

"""
The pagination offset to use
"""
offset: Int = 0
"""
The number of records to return after the pagination offset. This uses the default neo4j ordering
"""
first: Int = 20000
// """
// The pagination offset to use
// """
// offset: Int = 0
// """
// The number of records to return after the pagination offset. This uses the default neo4j ordering
// """
// first: Int = 20000

"""
The unique identification code for the capability. When creating a new capability,
choose a lower case, hyphenated string similar to the name people call the capability.
// """
// The unique identification code for the capability. When creating a new capability,
// choose a lower case, hyphenated string similar to the name people call the capability.

"""
code: String
"""
The name generally used to refer to the capability.
// """
// code: String
// """
// The name generally used to refer to the capability.

"""
namette: String
// """
// namette: String

): [BusinessCapability]
// ): [BusinessCapability]

}
// }

`,
];
console.log('emiting');
schemaEmitter.emit('schemaUpdate', getAugmentedSchema());
}, 5000);
// `,
// ];
// console.log('emiting');
// schemaEmitter.emit('schemaUpdate', getAugmentedSchema());
// }, 5000);
Loading

0 comments on commit a864c9c

Please sign in to comment.