Add missing import script
This commit is contained in:
parent
f6cc6f6a83
commit
f312cebb67
|
|
@ -0,0 +1,53 @@
|
|||
// import {makeExecutableSchema} from '@graphql-tools/schema';
|
||||
// import {addMocksToSchema} from '@graphql-tools/mock';
|
||||
// import {graphql} from 'graphql';
|
||||
|
||||
// const schemaString = '';
|
||||
|
||||
interface GraphQLBody {
|
||||
operationName: string
|
||||
}
|
||||
|
||||
interface CypressAliasRequest extends Request {
|
||||
alias?: string;
|
||||
}
|
||||
|
||||
interface GraphQLRequestPayload {
|
||||
operationName: string;
|
||||
query: string;
|
||||
variables: any;
|
||||
}
|
||||
|
||||
const isGraphQLBody = (body: any): body is GraphQLBody => {
|
||||
return (body as GraphQLBody).operationName !== undefined;
|
||||
};
|
||||
|
||||
export const hasOperationName = (req: Request, operationName: string) => {
|
||||
const {body} = req;
|
||||
return isGraphQLBody(body) && body.operationName === operationName;
|
||||
};
|
||||
|
||||
export const aliasQuery = (req: CypressAliasRequest, operationName: string) => {
|
||||
if (hasOperationName(req, operationName)) {
|
||||
req.alias = `gql${operationName}Query`;
|
||||
}
|
||||
};
|
||||
|
||||
export const aliasMutation = (req: CypressAliasRequest, operationName: string) => {
|
||||
if (hasOperationName(req, operationName)) {
|
||||
req.alias = `gql${operationName}Mutation`;
|
||||
}
|
||||
};
|
||||
|
||||
// export const makeRequest = (req: CypressAliasRequest, alias: string) => {
|
||||
// const schema = makeExecutableSchema({typeDefs: schemaString});
|
||||
// const schemaWithMocks = addMocksToSchema({schema});
|
||||
//
|
||||
// const {body} = req;
|
||||
//
|
||||
// o;
|
||||
// const paylaod = JSON.parse(body);
|
||||
//
|
||||
// return graphql(schemaWithMocks, query)
|
||||
// .then(result => result);
|
||||
// };
|
||||
Loading…
Reference in New Issue