2.0.0 • Published 4 years ago

graphql-fragment-to-json v2.0.0

Weekly downloads
41
License
-
Repository
github
Last release
4 years ago

Graphql Fragment to JSON

Convert a graphql fragment to json object

Install

npm install graphql-fragment-to-json

# OR

yarn add graphql-fragment-to-json

Quick start

import graphqlFragmentToJson from "graphql-fragment-to-json";
import gql from "graphql-tag";

const UserFragment = gql`
  fragment UserFragment on User {
    username
    first_name
    last_name
    addressInformation {
      address
      postal_code {
        id
        postal_code
        city
      }
    }
  }
`;

console.log(graphqlFragmentToJson({
  fragmentName: "UserFragment",
  definitions: UserFragment.definitions
}));
/* output
  username: undefined
  first_name: undefined
  last_name: undefined
  addressInformation:
    address: undefined
    postal_code:
      id: undefined
      postal_code: undefined
      city: undefined
*/

// You can choose a default value other than undefined like this
console.log(graphqlFragmentToJson({
  fragmentName: "UserFragment",
  definitions: UserFragment.definitions,
  defaultValue: ""
}));
/* output
  username: ""
  first_name: ""
  last_name: ""
  addressInformation:
    address: ""
    postal_code:
      id: ""
      postal_code: ""
      city: ""
*/

Contributing

Commits

This project use Commitizen, to commit to the project you can run the command :

yarn commit

Install and run

With docker (recommended)

Install in local env

yarn && yarn c42 install

Run tests

yarn c42 node:test

Without docker

require node 12 (node 10 is probably compatible)

Install in local env

yarn

# or

npm install

Run tests

yarn test

# or

npm run test
2.0.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago