Commit 3e7166ab authored by Vitaly Slobodin's avatar Vitaly Slobodin

Merge branch 'improve-jest-integration-with-graphql-schema-file' into 'master'

Add gitlab_schema.gql warning in integration spec

See merge request gitlab-org/gitlab!57375
parents e6fc1a57 930ea01a
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'); const baseConfig = require('./jest.config.base');
checkEnvironment();
module.exports = { module.exports = {
...baseConfig('spec/frontend_integration', { ...baseConfig('spec/frontend_integration', {
moduleNameMapper: { moduleNameMapper: {
......
import { buildSchema, graphql } from 'graphql'; 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 // The graphql schema is dynamically generated in CI
// during the `graphql-schema-dump` job. // during the `graphql-schema-dump` job.
import gitlabSchemaStr from '../../../../tmp/tests/graphql/gitlab_schema.graphql'; // eslint-disable-next-line global-require, import/no-unresolved
/* eslint-enable import/no-unresolved */ const getGraphqlSchema = () => require('../../../../tmp/tests/graphql/gitlab_schema.graphql');
const graphqlSchema = buildSchema(gitlabSchemaStr.loc.source.body);
const graphqlResolvers = { const graphqlResolvers = {
project({ fullPath }, schema) { project({ fullPath }, schema) {
const result = schema.projects.findBy({ path_with_namespace: fullPath }); const result = schema.projects.findBy({ path_with_namespace: fullPath });
...@@ -21,6 +19,7 @@ const graphqlResolvers = { ...@@ -21,6 +19,7 @@ const graphqlResolvers = {
}; };
}, },
}; };
const buildGraphqlSchema = memoize(() => buildSchema(getGraphqlSchema().loc.source.body));
export const graphqlQuery = (query, variables, schema) => 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