2020-08-06 17:10:15 -04:00
|
|
|
import { buildSchema, graphql } from 'graphql';
|
2021-03-25 17:09:13 -04:00
|
|
|
import { memoize } from 'lodash';
|
2021-02-19 10:10:30 -05:00
|
|
|
|
2021-10-04 23:11:53 -04:00
|
|
|
// eslint-disable-next-line global-require
|
2021-03-25 17:09:13 -04:00
|
|
|
const getGraphqlSchema = () => require('../../../../tmp/tests/graphql/gitlab_schema.graphql');
|
2020-08-06 17:10:15 -04:00
|
|
|
|
|
|
|
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-03-25 17:09:13 -04:00
|
|
|
const buildGraphqlSchema = memoize(() => buildSchema(getGraphqlSchema().loc.source.body));
|
2020-08-06 17:10:15 -04:00
|
|
|
|
|
|
|
export const graphqlQuery = (query, variables, schema) =>
|
2021-03-25 17:09:13 -04:00
|
|
|
graphql(buildGraphqlSchema(), query, graphqlResolvers, schema, variables);
|