Skip to content

creates a normalizr schema for a graphql query from a graphql schema

Notifications You must be signed in to change notification settings

eyston/normalizr-graphql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

normalizr-graphql

Uses the normalizr library to normalize a GraphQL query response. It is built as a babel-plugin which turns a GraphQL query into an object with a schema and string property. The schema is a normalizr schema which can be passed to normalize and the string is the query string which may have been modified to add id and __typename where appropriate.

An example use:

import NormalizeQL from 'normalize-graphql';
import {normalize} from 'normalizr';
import {graphql} from 'graphql';
import schema from './data/schema';

let query = NormalizeQL`{
  query {
    group(id: 1) {
      name
      owner {
        name
      }
      members {
        ...on User {
          name
        }
        ...groupFields
      }
    }
  }

  fragment groupFields on Group {
    name
    owner {
      name
    }
  }
}`;

let response = await graphql(schema, query.string, {});
let result = normalize(response, query.schema);

// result is now normalized with Group and User entities

About

creates a normalizr schema for a graphql query from a graphql schema

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published