Commit 930ea01a authored by Paul Slaughter's avatar Paul Slaughter

Add gitlab_schema.gql warning in integration spec

- A missing gitlab_schema.graphql file can cause
  unrelated and hard to debug issues.
- This can be overwritten with GL_IGNORE_WARNINGS=1
parent 62a3697e
const fs = require('fs');
const isESLint = require('./is_eslint');
const GRAPHQL_SCHEMA_PATH = 'tmp/tests/graphql/gitlab_schema.graphql';
const GRAPHQL_SCHEMA_JOB = 'bundle exec rake gitlab:graphql:schema:dump';
const shouldIgnoreWarnings = JSON.parse(process.env.GL_IGNORE_WARNINGS || '0');
const failCheck = (message) => {
console.error(message);
if (!shouldIgnoreWarnings) {
process.exit(1);
}
};
const checkGraphqlSchema = () => {
if (!fs.existsSync(GRAPHQL_SCHEMA_PATH)) {
const message = `
ERROR: Expected to find "${GRAPHQL_SCHEMA_PATH}" but file does not exist. Try running:
${GRAPHQL_SCHEMA_JOB}
`;
failCheck(message);
}
};
const check = () => {
if (isESLint(module)) {
return;
}
checkGraphqlSchema();
};
module.exports = check;
const checkEnvironment = require('./config/helpers/check_frontend_integration_env');
const baseConfig = require('./jest.config.base');
checkEnvironment();
module.exports = {
...baseConfig('spec/frontend_integration', {
moduleNameMapper: {
......
import { buildSchema, graphql } from 'graphql';
import { memoize } from 'lodash';
/* eslint-disable import/no-unresolved */
// This rule is disabled for the following line.
// The graphql schema is dynamically generated in CI
// during the `graphql-schema-dump` job.
import gitlabSchemaStr from '../../../../tmp/tests/graphql/gitlab_schema.graphql';
/* eslint-enable import/no-unresolved */
// eslint-disable-next-line global-require, import/no-unresolved
const getGraphqlSchema = () => require('../../../../tmp/tests/graphql/gitlab_schema.graphql');
const graphqlSchema = buildSchema(gitlabSchemaStr.loc.source.body);
const graphqlResolvers = {
project({ fullPath }, schema) {
const result = schema.projects.findBy({ path_with_namespace: fullPath });
......@@ -21,6 +19,7 @@ const graphqlResolvers = {
};
},
};
const buildGraphqlSchema = memoize(() => buildSchema(getGraphqlSchema().loc.source.body));
export const graphqlQuery = (query, variables, schema) =>
graphql(graphqlSchema, query, graphqlResolvers, schema, variables);
graphql(buildGraphqlSchema(), query, graphqlResolvers, schema, variables);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment