File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed
Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,12 @@ function resetCaches() {
2424 fragmentSourceMap = { } ;
2525}
2626
27+ // For defining doc.toString
28+ function toString ( loc ) {
29+ return loc . source . body ;
30+
31+ }
32+
2733// Take a unstripped parsed document (query/mutation or even fragment), and
2834// check all fragment definitions, checking for name->source uniqueness.
2935// We also want to make sure only unique fragments exist in the document.
@@ -135,6 +141,7 @@ function parseDocument(doc) {
135141 // existing fragments of the same name
136142 parsed = processFragments ( parsed ) ;
137143 parsed = stripLoc ( parsed , false ) ;
144+ parsed . toString = toString . bind ( null , parsed . loc ) ;
138145 docCache [ cacheKey ] = parsed ;
139146
140147 return parsed ;
Original file line number Diff line number Diff line change @@ -438,6 +438,13 @@ const assert = require('chai').assert;
438438 } ) ;
439439 } ) ;
440440
441+ it ( 'returned document toString returns query string' , ( ) => {
442+ const query = `{ user(id: 5) { firstName lastName } }` ;
443+ const doc = gql ( query ) ;
444+
445+ assert . equal ( doc . toString ( ) , query ) ;
446+ } ) ;
447+
441448 // How to make this work?
442449 // it.only('can reference a fragment passed as a document via shorthand', () => {
443450 // const ast = gql`
You can’t perform that action at this time.
0 commit comments