Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apollo-link-response-resolver

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-link-response-resolver

Use resolvers to format incoming data with Apollo Link

  • 0.2.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Automatically format incoming GraphQL query data with Apollo Client

Remote data from an external API doesn't always line up with the format we expect it to be in. From enum values not corresponding to their client-side string representation to float values not being return as a currency string, there are many cases where you need to automatically format incoming data.

apollo-link-response-resolver is a solution to this problem using a resolver format that GraphQL and Redux users will be comfortable with. You create your resolvers map and hook apollo-link-response-resolver in to ApolloClient and the rest is automatic--all incoming response data will be formatted based on the resolvers you provided.

Quick Start

To get started, install apollo-link-response-resolver from npm:

npm install -S apollo-link-response-resolver

The rest of the instructions assume that you have already set up Apollo Client in your application. After you install the package, you can create your response resolver by calling responseResolver and passing in a resolver map. A resolver map describes how to update the fields on each type of data.

Let's look at a simple example where we're updating the fullname field on all pieces of data coming from the server with the Account type:

import { withResponseResolver } from 'apollo-link-response-resolver'

const resolvers = {
  Account: {
    fullname: name => name.toUpperCase(),
  },
}

const responseResolverLink = withResponseResolver(resolvers)

To hook up your response resolvers to Apollo Client, add your link to the other links in your Apollo Link chain. You want to make sure that your link comes before HttpLink.

const client = new ApolloClient({
  cache,
  link: ApolloLink.from([responseResolverLink, new HttpLink()]),
})

Example Application

TODO

Keywords

FAQs

Package last updated on 15 Sep 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc