Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to execute LIST_ query with NoPagination #65

Open
Ruben-deBruijn opened this issue Apr 12, 2022 · 0 comments
Open

Fails to execute LIST_ query with NoPagination #65

Ruben-deBruijn opened this issue Apr 12, 2022 · 0 comments

Comments

@Ruben-deBruijn
Copy link

Following error message is provided:

Error: Failed to execute query LIST_WATCHES.
    at Object.paginate (/Users/rubendebruijn/schaap_citroen_v2/node_modules/gatsby-graphql-source-toolkit/src/source-nodes/fetch-nodes/paginate.ts:60:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at fetchNodeList (/Users/rubendebruijn/schaap_citroen_v2/node_modules/gatsby-graphql-source-toolkit/src/source-nodes/fetch-nodes/fetch-lists.ts:61:20)
    at Object.fetchAllNodes
(/Users/rubendebruijn/schaap_citroen_v2/node_modules/gatsby-graphql-source-toolkit/src/source-nodes/fetch-nodes/fetch-lists.ts:36:24)
    at Object.createNodes
(/Users/rubendebruijn/schaap_citroen_v2/node_modules/gatsby-graphql-source-toolkit/src/source-nodes/node-actions/create-nodes.ts:13:20)
    at async Promise.all (index 0)
    at sourceAllNodes (/Users/rubendebruijn/schaap_citroen_v2/node_modules/gatsby-graphql-source-toolkit/src/source-nodes/source-all-nodes.ts:20:3)
    at Object.exports.sourceNodes (/Users/rubendebruijn/schaap_citroen_v2/gatsby-node.js:99:3)
    at runAPI (/Users/rubendebruijn/schaap_citroen_v2/node_modules/gatsby/src/utils/api-runner-node.js:462:16)

As described in the guide, i implemented a PaginationAdapter that doesn't require variables. There is no pagination implemented in the BE i connect with.

Still, i would love to automaticly generate the fragments with generateDefaultFragments This issue doesn't seem to appear when i write a fragment manually and generate it with readOrGenerateDefaultFragments

Approach:

const NoPagination = {
  name: "NoPagination",
  expectedVariableNames: [],
  start() {
      return {
          variables: {},
          hasNextPage: true,
      };
  },
  next() {
      return {
          variables: {},
          hasNextPage: false,
      };
  },
  concat(result) {
      return result;
  },
  getItems(pageOrResult) {
      return pageOrResult;
  },
}

async function createSourcingConfig(gatsbyApi) {
  const execute = createDefaultQueryExecutor(`https://mywatchapi.com/graphql`);
  const schema = await loadSchema(execute)

const gatsbyNodeTypes = [
  {
    remoteTypeName: `Watch`,
    queries: `
      query LIST_WATCHES {
        watches { 
            ..._WatchId_ 
         }
      }
      fragment _WatchId_ on Watch {
          __typename 
          id 
      }
    `,
  },
]

  const fragments = await generateDefaultFragments({ schema, gatsbyNodeTypes })
  
  const documents = compileNodeQueries({
    schema,
    gatsbyNodeTypes,
    customFragments: fragments,
  })

  return {
    gatsbyApi,
    schema,
    execute,
    gatsbyTypePrefix: `Example`,
    gatsbyNodeDefs: buildNodeDefinitions({ gatsbyNodeTypes, documents }),
    paginationAdapters: [NoPagination],
  }
}

Expected

sourceAllNodes will run succesfuly, while the fragment generated automaticly

Actual

sourceAllNodes runs, but no nodes were created and error is thrown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant