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() {
24
24
fragmentSourceMap = { } ;
25
25
}
26
26
27
+ // For defining doc.toString
28
+ function toString ( loc ) {
29
+ return loc . source . body ;
30
+
31
+ }
32
+
27
33
// Take a unstripped parsed document (query/mutation or even fragment), and
28
34
// check all fragment definitions, checking for name->source uniqueness.
29
35
// We also want to make sure only unique fragments exist in the document.
@@ -135,6 +141,7 @@ function parseDocument(doc) {
135
141
// existing fragments of the same name
136
142
parsed = processFragments ( parsed ) ;
137
143
parsed = stripLoc ( parsed , false ) ;
144
+ parsed . toString = toString . bind ( null , parsed . loc ) ;
138
145
docCache [ cacheKey ] = parsed ;
139
146
140
147
return parsed ;
Original file line number Diff line number Diff line change @@ -438,6 +438,13 @@ const assert = require('chai').assert;
438
438
} ) ;
439
439
} ) ;
440
440
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
+
441
448
// How to make this work?
442
449
// it.only('can reference a fragment passed as a document via shorthand', () => {
443
450
// const ast = gql`
You can’t perform that action at this time.
0 commit comments