LearnApplyShare

graphql 쿼리객체 문자열 변환

August 27, 2019 - [graphql]

그래프큐엘 쿼리 객체를 문자열로 변환하는 방법

하나,

const myFragment = gql` .....some GQL... `;

console.log(getGqlString(myFragment));

function getGqlString(doc: DocumentNode) {
  return doc.loc && doc.loc.source.body;
}

둘,

import { print } from 'graphql/language/printer'

console.log(print(query)) 

Ref.

https://github.com/apollographql/graphql-tag/issues/144