2020-10-24 23:57:45 +05:30
|
|
|
import { buildSchema, graphql } from 'graphql';
|
2021-04-29 21:17:54 +05:30
|
|
|
import { memoize } from 'lodash';
|
2021-04-17 20:07:23 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
// eslint-disable-next-line global-require
|
2021-04-29 21:17:54 +05:30
|
|
|
const getGraphqlSchema = () => require('../../../../tmp/tests/graphql/gitlab_schema.graphql');
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|
2021-04-29 21:17:54 +05:30
|
|
|
const buildGraphqlSchema = memoize(() => buildSchema(getGraphqlSchema().loc.source.body));
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
export const graphqlQuery = (query, variables, schema) =>
|
2021-04-29 21:17:54 +05:30
|
|
|
graphql(buildGraphqlSchema(), query, graphqlResolvers, schema, variables);
|