Make intercept work with mocks
This commit is contained in:
parent
3d630b28df
commit
e83ebb73a0
|
|
@ -27,7 +27,7 @@
|
|||
// https://github.com/tgriesser/cypress-graphql-mock/issues/23
|
||||
// todo: once above issue is fixed, go back to the original repo -> npm install cypress-graphql-mock
|
||||
// import 'cypress-graphql-mock';
|
||||
// import mocks from '../fixtures/mocks';
|
||||
import mocks from '../fixtures/mocks';
|
||||
|
||||
import {makeExecutableSchema} from '@graphql-tools/schema';
|
||||
import {addMocksToSchema} from '@graphql-tools/mock';
|
||||
|
|
@ -144,54 +144,28 @@ Cypress.Commands.add('openSidebar', () => {
|
|||
Cypress.Commands.add('setup', () => {
|
||||
cy.fakeLogin('nino.teacher', 'test');
|
||||
cy.viewport('macbook-15');
|
||||
// cy.task('getSchema').then(schemaString => {
|
||||
const schemaString = `
|
||||
schema {
|
||||
query: Query
|
||||
}
|
||||
|
||||
type Query {
|
||||
me: PrivateUserNode
|
||||
}
|
||||
|
||||
|
||||
interface Node {
|
||||
id: ID!
|
||||
}
|
||||
cy.task('getSchema').then(schemaString => {
|
||||
const schema = makeExecutableSchema({typeDefs: schemaString});
|
||||
const schemaWithMocks = addMocksToSchema({schema, mocks});
|
||||
|
||||
type PrivateUserNode implements Node {
|
||||
firstName: String!
|
||||
lastName: String!
|
||||
avatarUrl: String!
|
||||
}
|
||||
`;
|
||||
const schema = makeExecutableSchema({typeDefs: schemaString});
|
||||
const schemaWithMocks = addMocksToSchema({schema});
|
||||
|
||||
// cy.intercept('POST', '/api/graphql', (req) => {
|
||||
const query = `
|
||||
query MeQuery {
|
||||
me {
|
||||
firstName
|
||||
lastName
|
||||
avatarUrl
|
||||
}
|
||||
}
|
||||
`;
|
||||
// const {query, variables} = req.body;
|
||||
// console.log(query, variables);
|
||||
graphql({
|
||||
schema: schemaWithMocks,
|
||||
source: query,
|
||||
}).then(result => {
|
||||
console.log(result);
|
||||
// req.reply({
|
||||
// data: {},
|
||||
// });
|
||||
}, e => {
|
||||
console.log(e.message);
|
||||
console.error(e);
|
||||
cy.intercept('POST', '/api/graphql', (req) => {
|
||||
const {query, variables} = req.body;
|
||||
console.log(query, variables);
|
||||
graphql({
|
||||
schema: schemaWithMocks,
|
||||
source: query,
|
||||
variableValues: variables,
|
||||
}).then(result => {
|
||||
console.log('result');
|
||||
console.log(result);
|
||||
req.reply({
|
||||
...result,
|
||||
});
|
||||
}, e => {
|
||||
console.log('error message');
|
||||
console.log(e.message);
|
||||
console.error(e);
|
||||
});
|
||||
});
|
||||
// });
|
||||
// });
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue