Have to specify .as() alias when setting an endpoint
todda00 opened this issue · comments
When specifying an endpoint, an error is produced:
beforeEach(() => {
cy.server();
cy.mockGraphql({
schema: Cypress.env("GRAPHQL_SCHEMA"),
endpoint: "/api"
});
});
produces error:
CypressError: cy.get() could not find a registered alias for: '@mockGraphqlOps'.
Available aliases are: 'mockGraphqlOps:/api'.
Changing the cy.mockGraphql()
call to the following resolves the issue:
beforeEach(() => {
cy.server();
cy.mockGraphql({
schema: Cypress.env("GRAPHQL_SCHEMA"),
endpoint: "/api"
}).as("mockGraphqlOps");
});
If this is normal expected behavior, a note in the readme should be added to add .as(). As a newer user of Cypress this tripped me up.
I came in just to post something like this :D
@todda00 out of curiosity, what are you setting Cypress.env("GRAPHQL_SCHEMA") to?
Is that the string contents of a .graphql file?
Because that's what I'm trying to accomplish, and when the query gets run, I get a:
Error: Invalid or incomplete introspection result. Ensure that you are passing "data" property of introspection response and no "errors" was returned alongside
The GRAPHQL_SCHEMA contains the full schema.
Here is my process:
npm/yarn script to build the schema.graphql file:
npx graphql get-schema -e http://localhost:5666/api -o schema.graphql
in my cypress plugins file:
const env = dotenv.config({
path: path.resolve(__dirname, "../../../../.env/development.env")
});
cfg.env = env.parsed;
const schema = fs.readFileSync("schema.graphql", "utf8");
cfg.env.GRAPHQL_SCHEMA = schema;
Thanks 👍🏻 so, you don't get anything like the error I mentioned above?
I'm also doing something similar (loading a .graphql outputted by graphql tools), but for some reason it's not being parsed correctly.
Would it be ok if you share some pieces of your .graphql file, just to compare the format with mine? Maybe first couple lines? I'd really appreciate :-)
I haven't updated this in a while, it looks like I'm using 0.2.0 of this module but it works without error.
Here are the first few lines of my schema.graphql
# source: http://localhost:5666/api
# timestamp: Fri Apr 26 2019 08:21:45 GMT-0400 (EDT)
schema {
query: RootQuery
mutation: RootMutation
}
type ActivationCode {
code: String
expirationDate: Date
}
type CanvasImage {
fieldName: String
x: Float
y: Float
width: Float
height: Float
image: Image
}
input CanvasImageInput {
fieldName: String
x: Float
y: Float
width: Float
height: Float
image: ImageInput
}