Skip to content

[Question] Sample code for GraphQL.js tutorial #1631

@blue32a

Description

@blue32a

Hello

I have been working through the graphql.js tutorial, particularly the section on "Authentication and Express Middleware". I encountered an issue when trying to execute the API designed to return the caller's IP address. Unfortunately, instead of receiving the expected IP address, the API response was data: { ip: null }.

Here are the steps I followed:

  1. I set up the environment and dependencies as outlined in the tutorial.
  2. Followed the instructions in the "Authentication and Express Middleware" section to implement the API for returning the caller's IP address.
  3. Executed a query expecting to receive the caller's IP address in the response.

Expected Result:
I expected to receive a response containing the caller's IP address, similar to data: { ip: "caller's IP address" }.

Actual Result:
The response was data: { ip: null }, indicating that the IP address could not be retrieved or was not properly passed through the middleware.

var root = {
  ip: function (args, request) {
    return request.ip // request is undefined
  },
}

Dependencies:

  "dependencies": {
    "express": "^4.18.3",
    "graphql": "^16.8.1",
    "graphql-http": "^1.22.0",
    "ruru": "^2.0.0-beta.11"
  }

I double-checked the code and setup to ensure compliance with the tutorial instructions but could not identify any deviations or mistakes on my part that could cause this issue.

I would greatly appreciate any guidance or suggestions you could offer to resolve this issue. If there are any additional details or information you need, please let me know, and I'll be happy to provide them.

Thank you for your time and support.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions