@@ -155,6 +155,86 @@ async function test() {
155155 }
156156 };
157157}
158+ export type SdkWithHooks = ReturnType<typeof getSdkWithHooks>;` )
159+ } )
160+
161+ it ( 'Should generate the output from which mutation operation has been removed' , async ( ) => {
162+ const config : PluginsConfig = { }
163+ const document = parse ( /* GraphQL */ `
164+ query feed {
165+ feed {
166+ id
167+ commentCount
168+ repository {
169+ owner {
170+ avatar_url
171+ }
172+ }
173+ }
174+ }
175+ query feed2($v: String!) {
176+ feed {
177+ id
178+ }
179+ }
180+ query feed3($v: String) {
181+ feed {
182+ id
183+ }
184+ }
185+ query feed4($v: String! = "TEST") {
186+ feed {
187+ id
188+ }
189+ }
190+ mutation submitComment(
191+ $repoFullName: String!
192+ $commentContent: String!
193+ ) {
194+ submitComment(
195+ repoFullName: $repoFullName
196+ commentContent: $commentContent
197+ ) {
198+ ...CommentsPageComment
199+ }
200+ }
201+ fragment CommentsPageComment on Comment {
202+ id
203+ postedBy {
204+ login
205+ html_url
206+ }
207+ createdAt
208+ content
209+ }
210+ ` )
211+ const docs = [ { location : '' , document } ]
212+
213+ const content = ( await plugin ( schema , docs , config , {
214+ outputFile : 'graphql.ts' ,
215+ } ) ) as Types . ComplexPluginOutput
216+
217+ const usage = basicUsage
218+ const output = await validate ( content , config , docs , schema , usage )
219+ expect ( output )
220+ . toContain ( `export type Sdk = ReturnType<typeof getSdk>;export function getSdkWithHooks(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) {
221+ const sdk = getSdk(client, withWrapper);
222+ return {
223+ ...sdk,
224+ useFeed(key: SWRKeyInterface, variables?: FeedQueryVariables, config?: SWRConfigInterface<FeedQuery>) {
225+ return useSWR<FeedQuery>(key, () => sdk.feed(variables), config);
226+ },
227+ useFeed2(key: SWRKeyInterface, variables: Feed2QueryVariables, config?: SWRConfigInterface<Feed2Query>) {
228+ return useSWR<Feed2Query>(key, () => sdk.feed2(variables), config);
229+ },
230+ useFeed3(key: SWRKeyInterface, variables?: Feed3QueryVariables, config?: SWRConfigInterface<Feed3Query>) {
231+ return useSWR<Feed3Query>(key, () => sdk.feed3(variables), config);
232+ },
233+ useFeed4(key: SWRKeyInterface, variables?: Feed4QueryVariables, config?: SWRConfigInterface<Feed4Query>) {
234+ return useSWR<Feed4Query>(key, () => sdk.feed4(variables), config);
235+ }
236+ };
237+ }
158238export type SdkWithHooks = ReturnType<typeof getSdkWithHooks>;` )
159239 } )
160240 } )
0 commit comments