Skip to content

eyston/normalizr-graphql

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 

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