Welcome to mirror list, hosted at ThFree Co, Russian Federation.

graphql.js « mock_server « test_helpers « frontend_integration « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 27396842523e529be5842d98725b8786c153acc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { buildSchema, graphql } from 'graphql';
import { memoize } from 'lodash';

// The graphql schema is dynamically generated in CI
// during the `graphql-schema-dump` job.
// eslint-disable-next-line global-require, import/no-unresolved
const getGraphqlSchema = () => require('../../../../tmp/tests/graphql/gitlab_schema.graphql');

const graphqlResolvers = {
  project({ fullPath }, schema) {
    const result = schema.projects.findBy({ path_with_namespace: fullPath });
    const userPermission = schema.db.userPermissions[0];

    return {
      ...result.attrs,
      userPermissions: {
        ...userPermission,
      },
    };
  },
};
const buildGraphqlSchema = memoize(() => buildSchema(getGraphqlSchema().loc.source.body));

export const graphqlQuery = (query, variables, schema) =>
  graphql(buildGraphqlSchema(), query, graphqlResolvers, schema, variables);