Skip to content

Exposing GraphQL APIs with nested queries enabled using OASGraph. #2153

@esoodev

Description

@esoodev

Hello, I am exposing GraphQL API for my current project using OASGraph, and am having issues querying for nested models when tested on GraphiQL.

What I Did

I currently have three models: User, GameProfile, and Game. Their relationships are as follows:

  • A User has many GameProfiles.
  • A GameProfile belongs to User and Game.
  • A Game has many GameProfiles.

It is my understanding that simply typing into the console npx oasgraph http://localhost:3000/openapi.json provided by the tutorial won't expose nested relationships, since OASGraph's default option for addSubOperation is false.

Therefore, after creating a GET route for /users/{id}/game-profiles for retrieving GameProfile model instances belong to User, and testing that it works as expected, I created my own OASGraph server following the guideline, creating the necessary schema as follows :

const oas = JSON.parse(
    await request.get('http://localhost:3000/openapi.json')
);
const { schema, report } = await createGraphQlSchema(oas, {
    addSubOperations: true
});

Current Behavior

Starting the server and navigating to GraphiQL I ran into two issues :

  1. The query won't recognize "users" as valid, and recommends that I query for "user" "users2" or "userCount."
  2. The output for the query is null.
query{
users2 {
	gameProfiles {
	  gameProfileId
	  gameProfileNickname
	  statusId
	  createdAt
	  userId
	  gameId
	}
}
}
{
  "data": {
    "users2": [
      {
        "gameProfiles": null
      }
    ]
  }
}

Comment

Would anyone have any idea as to why this might be happening? Your help is appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions