@@ -66,129 +66,13 @@ export function isModelQuery(
66
66
67
67
export function paginatedQueryV2 ( query : string ) : PaginatedQuery {
68
68
switch ( process . env . GRAPHQL_V2_PAGINATOR ) {
69
- case 'relay' :
70
- return paginatedWithRelayV2 ( query ) ;
71
69
case 'offset-limit' :
72
70
return paginateWithOffsetLimitV2 ( query ) ;
73
71
default :
74
72
return paginateWithKeysetV2 ( query ) ;
75
73
}
76
74
}
77
75
78
- /**
79
- * Paginates v2 graphql queries.
80
- */
81
- export function paginatedWithRelayV2 ( query : string ) : PaginatedQuery {
82
- const edgesPath : string [ ] = [ ] ;
83
- const pageInfoPath : string [ ] = [ ] ;
84
- let firstNode = true ;
85
- const ast = gql . visit ( gql . parse ( query ) , {
86
- Document ( node ) {
87
- if ( node . definitions . length !== 1 ) {
88
- throw invalidQuery (
89
- 'document should contain a single query operation definition'
90
- ) ;
91
- }
92
- } ,
93
- OperationDefinition ( node ) {
94
- if ( node . operation !== 'query' ) {
95
- throw invalidQuery ( 'only query operations are supported' ) ;
96
- }
97
-
98
- // Add pagination variables to query operation
99
- return createOperationDefinition ( node , [
100
- [ 'pageSize' , 'Int' ] ,
101
- [ 'cursor' , 'String' ] ,
102
- ] ) ;
103
- } ,
104
- Field : {
105
- enter ( node ) {
106
- if ( edgesPath . length ) {
107
- // Skip rest of nodes once edges path has been set
108
- return false ;
109
- } else if ( firstNode ) {
110
- firstNode = false ;
111
- const newNodeName = `${ node . name . value } _connection` ;
112
- pageInfoPath . push ( newNodeName , 'pageInfo' ) ;
113
- edgesPath . push ( newNodeName , EDGES ) ;
114
- // copy existing where args
115
- const existing = ( node . arguments ?? [ ] ) . filter ( ( n ) =>
116
- ALLOWED_ARG_TYPES . has ( n . name . value )
117
- ) ;
118
- return {
119
- kind : 'Field' ,
120
- name : { kind : 'Name' , value : newNodeName } ,
121
- // Add pagination arguments
122
- arguments : [
123
- ...existing ,
124
- {
125
- kind : 'Argument' ,
126
- name : { kind : 'Name' , value : 'first' } ,
127
- value : {
128
- kind : 'Variable' ,
129
- name : { kind : 'Name' , value : 'pageSize' } ,
130
- } ,
131
- } ,
132
- {
133
- kind : 'Argument' ,
134
- name : { kind : 'Name' , value : 'after' } ,
135
- value : {
136
- kind : 'Variable' ,
137
- name : { kind : 'Name' , value : 'cursor' } ,
138
- } ,
139
- } ,
140
- ] ,
141
- // Add pageInfo alongside the existing selection set
142
- selectionSet : {
143
- kind : 'SelectionSet' ,
144
- selections : [
145
- {
146
- kind : 'Field' ,
147
- name : { kind : 'Name' , value : EDGES } ,
148
- selectionSet : {
149
- kind : 'SelectionSet' ,
150
- selections : [
151
- {
152
- kind : 'Field' ,
153
- name : { kind : 'Name' , value : 'cursor' } ,
154
- } ,
155
- {
156
- kind : 'Field' ,
157
- name : { kind : 'Name' , value : 'node' } ,
158
- selectionSet : node . selectionSet ,
159
- } ,
160
- ] ,
161
- } ,
162
- } ,
163
- {
164
- kind : 'Field' ,
165
- name : { kind : 'Name' , value : 'pageInfo' } ,
166
- selectionSet : {
167
- kind : 'SelectionSet' ,
168
- selections : [
169
- {
170
- kind : 'Field' ,
171
- name : { kind : 'Name' , value : 'hasNextPage' } ,
172
- } ,
173
- ] ,
174
- } ,
175
- } ,
176
- ] ,
177
- } ,
178
- } ;
179
- }
180
- return undefined ;
181
- } ,
182
- } ,
183
- } ) ;
184
-
185
- return {
186
- query : gql . print ( ast ) ,
187
- edgesPath,
188
- pageInfoPath,
189
- } ;
190
- }
191
-
192
76
function createOperationDefinition (
193
77
node : gql . OperationDefinitionNode ,
194
78
varDefs : [ string , string ] [ ]
0 commit comments