Skip to content

Commit

Permalink
fix: return type of refetchQuery to the object with query and variables
Browse files Browse the repository at this point in the history
  • Loading branch information
playerx committed Dec 12, 2019
1 parent a1aa20e commit 4552aad
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import renderFragment from '../render/renderFragment'
import renderMethod from '../render/renderMethod'
import renderOptions from '../render/renderOptions'
import renderQuery from '../render/renderQuery'
import renderRefetchQueryResult from '../render/renderRefetchQueryResult'

export default function (
field: IntrospectionField,
Expand Down Expand Up @@ -66,7 +67,9 @@ export default function (
queryName,
variablesDeclarationString,
variablesString,
returnQuery: true,
}) +
renderRefetchQueryResult({
hasProps: hasInputs,
}),
})

Expand Down
5 changes: 2 additions & 3 deletions src/commands/graphql-client/generator/render/renderQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ export default function ({
queryName,
variablesDeclarationString,
variablesString,
returnQuery = false,
}) {
if (!hasFragment) {
return ` // build query
${returnQuery ? 'return' : 'const query ='} gql2\`
const query = gql2\`
query ${queryName}${variablesDeclarationString} {
${queryName}${variablesString}
}
Expand All @@ -16,7 +15,7 @@ export default function ({

return `
// build query
${returnQuery ? 'return' : 'const query ='} gql2\`
const query = gql2\`
query ${queryName}${variablesDeclarationString} {
${queryName}${variablesString} {
...\${fragmentName}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export default function ({
hasProps,
}: Props) {
if (hasProps) {
return `
return {
query,
variables: props,
}`
}

else {
return `
return {
query,
}`
}
}

interface Props {
hasProps: boolean
}

0 comments on commit 4552aad

Please sign in to comment.