File tree Expand file tree Collapse file tree 1 file changed +25
-18
lines changed Expand file tree Collapse file tree 1 file changed +25
-18
lines changed Original file line number Diff line number Diff line change @@ -51,24 +51,31 @@ export function parser(document: DocumentNode): IDocumentDefinition {
51
51
`to convert your operation into a document`
52
52
) ;
53
53
54
- const fragments = document . definitions . filter (
55
- ( x : DefinitionNode ) => x . kind === 'FragmentDefinition'
56
- ) ;
57
-
58
- const queries = document . definitions . filter (
59
- ( x : DefinitionNode ) =>
60
- x . kind === 'OperationDefinition' && x . operation === 'query'
61
- ) ;
62
-
63
- const mutations = document . definitions . filter (
64
- ( x : DefinitionNode ) =>
65
- x . kind === 'OperationDefinition' && x . operation === 'mutation'
66
- ) ;
67
-
68
- const subscriptions = document . definitions . filter (
69
- ( x : DefinitionNode ) =>
70
- x . kind === 'OperationDefinition' && x . operation === 'subscription'
71
- ) ;
54
+ const fragments : DefinitionNode [ ] = [ ]
55
+ const queries : DefinitionNode [ ] = [ ]
56
+ const mutations : DefinitionNode [ ] = [ ]
57
+ const subscriptions : DefinitionNode [ ] = [ ]
58
+
59
+ for ( const x of document . definitions ) {
60
+ if ( x . kind === 'FragmentDefinition' ) {
61
+ fragments . push ( x ) ;
62
+ continue
63
+ }
64
+
65
+ if ( x . kind === 'OperationDefinition' ) {
66
+ switch ( x . operation ) {
67
+ case 'query' :
68
+ queries . push ( x ) ;
69
+ break ;
70
+ case 'mutation' :
71
+ mutations . push ( x ) ;
72
+ break ;
73
+ case 'subscription' :
74
+ subscriptions . push ( x ) ;
75
+ break ;
76
+ }
77
+ }
78
+ }
72
79
73
80
invariant (
74
81
! fragments . length ||
You can’t perform that action at this time.
0 commit comments