surveymonkey / graphql-ergonomock Goto Github PK
View Code? Open in Web Editor NEWAutomatic mocking of GraphQL queries
License: MIT License
Automatic mocking of GraphQL queries
License: MIT License
Hello again,
I might be misunderstanding something here, but I have issues using ErgonoMockedProvider
with several queries fetching the same object. Here's a minimal reproduction adapted from the example in the Readme:
import { render } from '@testing-library/react';
import { ErgonoMockedProvider } from 'graphql-ergonomock';
import { gql, useQuery } from '@apollo/client';
const schema = gql`
type Shape {
id: ID!
returnInt: Int
returnString: String
returnBoolean: Boolean
}
type Query {
getShape: Shape
}
`;
const QUERY = gql`
query MyQuery {
getShape {
id
returnString
returnBoolean
}
}
`;
const ANOTHER_QUERY = gql`
query AnotherQuery {
getShape {
id
returnInt
returnBoolean
}
}
`;
const MyComponent = () => {
const { loading, error, data } = useQuery(QUERY);
const { loading: anotherLoading, error: anotherError, data: anotherData } = useQuery(ANOTHER_QUERY);
if (loading || anotherLoading) return <p>Loading</p>;
if (error || anotherError) return <p>Error</p>;
return (
<div>
MyComponent.
<div>String: {data.getShape.returnString}</div>
<div>Boolean: {data.getShape.returnBoolean.toString()}</div>
<div>Int: {anotherData.getShape.returnInt}</div>
</div>
);
};
test('MyComponent can render the query results.', async () => {
const mocks = {
MyQuery: {
getShape: { returnString: 'John Doe' },
},
AnotherQuery: {
getShape: { returnInt: 5 },
},
};
const { findByText } = render(
<ErgonoMockedProvider schema={schema} mocks={mocks}>
<MyComponent />
</ErgonoMockedProvider>,
);
expect(await findByText(/String: John Doe/)).toBeVisible();
expect(await findByText(/Boolean: (true|false)/)).toBeVisible();
expect(await findByText(/Int: 5/)).toBeVisible();
});
The test fails because data
is undefined; if I remove the second query it works. The problem is the same if I don't supply any mocks
.
Thanks!
This mocking library is fantastic (although it sadly looks abandoned?), non-the-less it's the only functional dynamic mocks library I've found that still works for the most part.
I did find that it has issues with queries that use aliases though.
Take this query which works just fine.
query SiteCounts {
crm {
sitesConnection(condition: { active: true }, first: 1) {
totalCount
}
}
}
I can mock it lik this:
const mocks = {
SiteCounts: () => ({
crm: {
sitesConnection: {
totalCount: 1,
},
},
}),
}
but if I add an alias to it like this:
query SiteCounts {
crm {
sites: sitesConnection {
totalCount
}
activeSites: sitesConnection(condition: { active: true }, first: 1) {
totalCount
}
}
}
I can no longer mock it :(
const mocks = {
SiteCounts: () => ({
crm: {
activeSites: {
totalCount: 1,
},
},
}),
}
Doesn't work, and the original sitesConnection
mock would override both parts of the query.
I haven't found any other issues, or any mention in the code of alias
so I assume this was just never implemented.
But with the last update over 9 months ago, I'm guessing this project is dead? But I thought I'd create the ticket anyway just in case.
Hello and thanks for a great library!
I'm trying to use ergonomock()
together with a MockedProvider
that uses addTypename=true
. This doesn't work out of the box because the results from ergonomock()
only includes __typename
if the query does, and we would like to avoid adding it to the latter manually.
Is there any chance of an addTypename
option to ergonomock
? If not do you have a suggestion for another solution?
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates are currently rate-limited. Click on a checkbox below to force their creation now.
@types/react
, @types/react-dom
, react
, react-dom
)These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
@types/react
, @types/react-dom
)jest
, ts-jest
).circleci/config.yml
node 4.7.0
package.json
fast-json-stable-stringify ^2.1.0
graphql ^15.0.0
seedrandom ^3.0.5
@apollo/client 3.4.8
@testing-library/jest-dom 5.14.1
@testing-library/react 11.2.7
@types/react 17.0.18
@types/react-dom 17.0.9
@types/seedrandom 3.0.1
jest 26.6.3
jest-extended 0.11.5
prettier 2.3.2
react 17.0.2
react-dom 17.0.2
semantic-release 17.4.5
ts-jest 26.5.6
typescript 4.3.5
There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.
Location: package.json
Error type: The renovate configuration file contains some invalid settings
Message: Invalid configuration option: author, Invalid configuration option: files, Invalid configuration option: keywords, Invalid configuration option: license, Invalid configuration option: main, Invalid configuration option: name, Invalid configuration option: packageRules[0].@apollo/client, Invalid configuration option: packageRules[0].@testing-library/jest-dom, Invalid configuration option: packageRules[0].@testing-library/react, Invalid configuration option: packageRules[0].@types/react, Invalid configuration option: packageRules[0].@types/react-dom, Invalid configuration option: packageRules[0].@types/seedrandom, Invalid configuration option: packageRules[0].jest, Invalid configuration option: packageRules[0].jest-extended, Invalid configuration option: packageRules[0].prettier, Invalid configuration option: packageRules[0].react, Invalid configuration option: packageRules[0].react-dom, Invalid configuration option: packageRules[0].semantic-release, Invalid configuration option: packageRules[0].ts-jest, Invalid configuration option: packageRules[0].typescript, Invalid configuration option: packageRules[1].fast-json-stable-stringify, Invalid configuration option: packageRules[1].graphql, Invalid configuration option: packageRules[1].graphql-tools, Invalid configuration option: packageRules[1].seedrandom, Invalid configuration option: renovate, Invalid configuration option: scripts, Invalid configuration option: version
Hey there 👋 I've been investigating using this package for a project I work on. I noticed the last commit was a while back so was wondering if this is still under use/development?
Thanks!
The latest graphql-ergonomock
release 1.2.0
is has a dependency to graph-tools
version ^7.0.0
.
This depends on a cross-fetch
version with an vulnerability: https://nvd.nist.gov/vuln/detail/CVE-2022-1365
Affected are cross-fetch
version >= 3.0.0, < 3.1.5
Is it possible to upgrade the graphql-tools
version or to remove the vulnerable dependency somehow and release those fixes?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.