Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
msw-introspection
Advanced tools
> Default mocked responses from a graphql query via msw and graphql introspection
msw-introspection
Default mocked responses from a graphql query via msw and graphql introspection
(introspection) -> (req,res,ctx) -> MockedResponse
Creates a msw handler for GraphQL operations. The handler returns mocked data that conforms to the schema types
Setup mocks
import { graphql } from "msw";
import { createIntrospectionHandler } from "msw-introspection";
import introspection from "../../graphql/introspection.json";
const introspectionHandler = createIntrospectionHandler(introspection);
const handlers = [graphql.operation(introspectionHandler)];
export const server = setupServer(...handlers);
Setup Jest
import "@testing-library/jest-dom/extend-expect";
import { client } from "./ApolloClient";
import { server } from "./mocks/server";
beforeAll(() => {
server.listen();
});
beforeEach(() => {
return client.clearStore();
});
afterEach(() => {
server.resetHandlers();
});
afterAll(() => {
server.close();
});
The testing for this library illustrates how to use MSW to mock a GQL API and get default responses from an introspected schema. The schema used for testing is provided by the SpaceX GraphQL API.
npm run download:schema
The /test
directory sets up an ApolloClient instance, a React component that calls useQuery
, and the utilities that set up the msw server.
├── test
│ ├── graphql
│ │ ├── introspection.json # Output of graphql-codegen
│ │ ├── schema.gql # Schema downloaded from SpaceX API
│ │ ├── types.d.ts # Output of graphql-codegen
│ ├── mocks # MSW code
│ ├── ApolloClient.ts # An instance of apollo client
│ ├── codegen.yml # Generate ts types and introspection from graphql schema
│ ├── index.test.tsx # Test suite
│ ├── rockets.tsx # Simple react component that makes a useQuery call.
│ ├── setupTests.ts # Enables mocking for unit tests via `beforeAll`/`afterAll` hooks.
FAQs
> Default mocked responses from a graphql query via msw and graphql introspection
The npm package msw-introspection receives a total of 0 weekly downloads. As such, msw-introspection popularity was classified as not popular.
We found that msw-introspection demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.