Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
graphql-mock
Advanced tools
This is a little library that helps with the apollo graphql projects testing.
Essentially it's a wrapper over the SchemaLink
to make it a bit more useful
in a React app testing schenario.
At the basic level it adds two things: an option to check which queries were sent, and mock responses.
npm add -D graphq-mock
thow this somewhere in your testing environment setup
import GraphQLMock from 'graphql-mock';
const schema = `
type Item {
id: ID!
name: String!
}
type Query {
items: [Item]
}
`;
const mocks = {
... // your regular apollo mocks
};
export default new GraphQLMock(schema, mocks);
Then use like so in your enzyme tests:
import { mount } from 'enzyme';
import { ApolloProvider } from 'react-apollo';
import { normalize } from 'graphql-mock';
import graphqlMock from './graphql';
import TodoList from 'src/my/component';
it('shoulda render alright', () => {
const query = `
query GetItems {
items {
id
name
}
}
`;
graqhqlMock.expect(query).reply({
items: [
{ id: '1', name: 'one' },
{ id: '2', name: 'two' }
]
})
const wrapper = mount(
<ApolloProvider client={graphqlMock.client}>
<TodoList />
</ApolloProvider>
);
expect(wrapper.html()).toEqual('<ul><li>one</li><li>two</li></ul>');
expect(graphqlMock.lastQuery).toEqual(normalize(query));
});
#client
-> a reference to the underline ApolloClient instance
#reset()
-> to reset all the mocks and queries history
#queries
-> the list of (string and normalized) queries that sent to the endpoint
#requests
-> requests (queries + variables) that sent to the server
#expect(query: string)
-> an API to mock the exact responses
also some helper functions:
import { parse, stringify, normalize } from 'graphql-mock';
parse(query) // turns a string query into an object
stringify(query) // turns an object into a standardly formatted string query
normalize(query) // turns an object or string query into a standard formatted string query
All code in this library released under the terms of the MIT license
Copyright (C) 2018 Nikolay Nemshilov
FAQs
GraphQL endpoint mockery library for testing
The npm package graphql-mock receives a total of 230 weekly downloads. As such, graphql-mock popularity was classified as not popular.
We found that graphql-mock demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.