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

Example with-graphql-hooks broken request #20474

Closed
tayloraucoin opened this issue Dec 25, 2020 · 3 comments · Fixed by #20929
Closed

Example with-graphql-hooks broken request #20474

tayloraucoin opened this issue Dec 25, 2020 · 3 comments · Fixed by #20929
Labels
examples Issue/PR related to examples good first issue Easy to fix issues, good for newcomers

Comments

@tayloraucoin
Copy link

Bug report

Describe the bug

Two issues:

Issue 1 - On creating example app, initial load is broken with error. Error serializing .initialGraphQLState["6gftu9"].data returned from getStaticProps in "/". Reason: undefined cannot be serialized as JSON. Please use null or omit this value. This is from the undefined value in the return not being JSON parsable (see https://dev.to/ryyppy/reason-records-nextjs-undefined-and-getstaticprops-5d46). The request during this initial load of the example is returning a 502.

Issue 2 - Broken request to existing api using code in example. When utilizing the logic in the example into an existing minimal next.js boilerplate, 400 bad request is continually returned throughout troubleshooting attempts.

error: {
    httpError: {
      status: 400,
      statusText: 'Bad Request',
      body: '{"errors":[{"message":"body.charCodeAt is not a function"}]}'
    }
  }

The api url is an existing app api that I can confirm the function in graphiql. Testing query is a minimal test example that is proven valid in the graphiql.

Here are the request inputs:

query {
  kind: 'Document',
  definitions: [
    {
      kind: 'OperationDefinition',
      operation: 'query',
      name: [Object],
      variableDefinitions: [Array],
      directives: [],
      selectionSet: [Object]
    }
  ],
  loc: { start: 0, end: 128 }
}
operation {
  query: {
    kind: 'Document',
    definitions: [ [Object] ],
    loc: { start: 0, end: 128 }
  },
  variables: { count: 5 },
  operationName: undefined,
  persisted: undefined
}
opts { useCache: true, variables: { count: 5 } }

Here is the query (if it helps):

import gql from "graphql-tag";

export default gql`
  query getCreators($count: Int) {
    creators(first: $count) {
      nodes {
        name
      }
      totalCount
    }
  }
`;

All of the files used are as they are in the example repo.

When watching my api logs, no requests are hitting the api

To Reproduce

Issue 1 - Broken initial code in example

  1. npx create-next-app --example with-graphql-hooks with-graphql-hooks-app
  2. npm i
  3. npm run dev
  4. view localhost:3000 to see error

Issue 2 - Broken request to existing api using code in example

  1. npx create-next-app --example with-graphql-hooks with-graphql-hooks-app
  2. npm i
  3. change url in graphql-client.js to existing api of your choice
  4. add query of your choice for api
  5. npm run dev
  6. view localhost:3000 to see error

Expected behavior

  1. Expect example to return valid values and render example ui

  2. Expect data to be present in api return for valid queries

System information

  • OS: macOS Mojave 10.14.4
  • Chrome 87.0.4280.88
  • Next.js: 10.0.0
  • Node.js: 12.14.0

Merry Christmas! 🎅

@tayloraucoin tayloraucoin added the bug Issue was opened via the bug report template. label Dec 25, 2020
@timneutkens timneutkens added good first issue Easy to fix issues, good for newcomers examples Issue/PR related to examples and removed bug Issue was opened via the bug report template. labels Jan 3, 2021
@tarunama
Copy link
Contributor

tarunama commented Jan 8, 2021

@tayloraucoin

Issue 1 - On creating example app, initial load is broken with error

This issue was maybe solved by changing request URL.
Response's HTTP status code 502, we need permission to fix this issue, Or use testing API.

@ludofischer
Copy link
Contributor

If anyone still needs this, they can check my branch #20929. It works at least with the same example API as the Apollo example. I think the upvoting feature feels sluggish could do with some optimistic updates that the graphql-hooks does not provide by default, but as the original example did not implement it I did not either.

@kodiakhq kodiakhq bot closed this as completed in #20929 Jan 11, 2021
kodiakhq bot pushed a commit that referenced this issue Jan 11, 2021
Fixes #20474

* Switch API url to working URL used in apollo example
* Update deps
* Move styled jsx out of the way to avoid demonstrating too many
  unfamiliar concepts at once

dev, build and start work now.
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
examples Issue/PR related to examples good first issue Easy to fix issues, good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants