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