Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
apollo-link-schema
Advanced tools
Changelog
apollo-link 1.2.5
ExecutionResult
on FetchResult
. <br/>
@rosskevin in #804Readme
The schema link provides a graphql execution environment, which allows you to perform GraphQL operations on a provided schema. This type of behavior is commonly used for server-side rendering (SSR) to avoid network calls and mocking data. While the schema link could provide graphql results on the client, currently the graphql execution layer is too heavy weight for practical application. To unify your state management with client-side GraphQL operations, you should use apollo-link-state, because it integrates with the Apollo Client cache and is much more lightweight.
npm install apollo-link-schema --save
When performing SSR on the same server you can use this library to avoid making network calls.
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { SchemaLink } from 'apollo-link-schema';
import schema from './path/to/your/schema';
const graphqlClient = new ApolloClient({
ssrMode: true,
cache: new InMemoryCache(),
link: new SchemaLink({ schema })
});
For more detailed information about mocking, please look the graphql-tools documentation.
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { SchemaLink } from 'apollo-link-schema';
import { makeExecutableSchema, addMockFunctionsToSchema } from 'graphql-tools';
const typeDefs = `
Query {
...
}
`;
const mocks = {
Query: () => ...,
Mutation: () => ...
};
const schema = makeExecutableSchema({ typeDefs });
addMockFunctionsToSchema({
schema,
mocks
});
const apolloCache = new InMemoryCache(window.__APOLLO_STATE__);
const graphqlClient = new ApolloClient({
cache: apolloCache,
link: new SchemaLink({ schema })
});
The SchemaLink
constructor can be called with an object with the following properties:
schema
: an executable graphql schemarootValue
: the root value that is passed to the resolvers (i.e. the first parameter for the rootQuery)context
: an object passed to the resolvers, following the graphql specification or a function that accepts the operation and returns the resolver context. The resolver context may contain all the data-fetching connectors for an operation.FAQs
Use a GraphQL Schema to request data
We found that apollo-link-schema demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 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
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).