Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
@stackworx/relay-mock-network-layer
Advanced tools
Relay modern network layer that returns schema correct mock data
Provides a network layer for relay modern that returns schema-correct mock data using addMockFunctionsToSchema
from graphql-tools
;
This is useful for working in an environment like storybook where you want to work on your components without hitting a live GraphQL server.
import {
Environment,
Network,
RecordSource,
Store
} from 'relay-runtime';
import getNetworkLayer from 'relay-mock-network-layer';
import schema from './graphql.schema.json';
const network = Network.create(getNetworkLayer({
schema,
// pass custom mocks as documented in graphql-tools
// http://dev.apollodata.com/tools/graphql-tools/mocking.html#Customizing-mocks
mocks: {
Geography: () => ({
id: '2',
countries: [{
abbreviation: 'US',
name: 'United States'
}, {
abbreviation: 'UK',
name: 'United Kingdom'
}],
usStates: [{
abbreviation: 'NY',
name: 'New York'
}, {
abbreviation: 'NJ',
name: 'New Jersey'
}]
}),
Address: () => ({
country: 'US',
city: 'New York',
state: 'NY',
zipCode: '10012',
})
},
// See https://www.apollographql.com/docs/graphql-tools/mocking.html#Mocking-interfaces
preserveResolvers: false,
// Forward along other options to `makeExecutableSchema`.
...schemaDefinitionOptions
}));
// Create an environment using this network:
const store = new Store(new RecordSource());
const environment = new Environment({network, store});
// use environment in <QueryRenderer>
If your schema has custom scalar types you'll need to use the resolvers
option to ensure those types get mocked correctly. Pass this option an object containing a resolve function for each custom scalar.
...
import getNetworkLayer from 'relay-mock-network-layer';
import {GraphQLScalarType} from 'graphql';
...
getNetworkLayer({
schema,
mocks: {...},
resolvers: {
CustomScalar: new GraphQLScalarType({
name: 'CustomScalar',
parseLiteral: () => {},
parseValue: () => {},
serialize: () => {}
}),
CustomScalar2: ...
}
});
FAQs
Relay modern network layer that returns schema correct mock data
We found that @stackworx/relay-mock-network-layer 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
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.