Ben Irvin 13a2f8b246
feat: Upgrade to Apollo v4
* feat: update and make build work

BREAKING CHANGE: Update from 'apollo-server-koa' to '@apollo/server' and '@as-integrations/koa'

* chore: fix comments

* chore: upgrade graphql-upload package

* chore: fix for body type unknown

* chore: remove old comment

* chore: clean up error handling

* chore: fix comment

* fix: http status codes for input validation errors

* fix: remove unused import

* fix: remove accidental bodyparser

* fix: add new required header to tests

* chore: standardize directive key names to be kebab-case

* test: add some extra message validation

* chore: remove devdep for koa-cors typings

* fix: add unknown error name

* fix: yarn.lock

* fix: add typings

* fix: typings

* fix: typings again

* fix: remove unused imports

* chore: remove unused import

* chore: move playground check to a service

* fix: package imports and versions

* chore: fix yarn.lock

* chore: fix types

* chore: clean up koa typings

* chore: koa typing cleanup

* chore: cleanup koa typings

* chore: more koa type cleanup

* chore: revert missing imports

* chore: cleanup koa typings

* chore: update yarn.lock
2024-01-15 14:54:58 +01:00

40 lines
999 B
JavaScript

'use strict';
const { createAgent } = require('./agent');
const { superAdmin } = require('./strapi');
const CONTENT_API_URL_PREFIX = '/api';
const createRequest = ({ strapi } = {}) => createAgent(strapi);
const createContentAPIRequest = ({ strapi, auth = {} } = {}) => {
const { token } = auth;
if (token) {
return createAgent(strapi, { urlPrefix: CONTENT_API_URL_PREFIX, token });
}
// Default content api agent
return createAgent(strapi, { urlPrefix: CONTENT_API_URL_PREFIX, token: 'test-token' });
};
const createAuthRequest = ({ strapi, userInfo = superAdmin.credentials, state }) => {
return createAgent(strapi, state).login(userInfo);
};
const transformToRESTResource = (input) => {
if (Array.isArray(input)) {
return input.map((value) => transformToRESTResource(value));
}
const { id, ...attributes } = input;
return { id, attributes };
};
module.exports = {
createRequest,
createContentAPIRequest,
createAuthRequest,
transformToRESTResource,
};