Ronier Ramos Sanchez
Ronier Ramos Sanchez

Reputation: 11

consume a REST API through KeyStoneJS v6

I'm dealing with a bit of a weird use case. I am using KeyStoneJS v6, through which I must interact with a REST API, make "GET" and "POST" requests, and return the data obtained to my NextJS client through my graphql api. I have found some examples but they use old versions of KeyStone and I can't figure out how to integrate it into my current project. I can't find references in the official documentation or on the internet, so I would appreciate any hints on how to proceed. Greetings in advance.

Upvotes: 1

Views: 607

Answers (1)

Molomby
Molomby

Reputation: 6559

That doesn't sound like a weird use case; you need to extend your GraphQL schema with some custom queries or mutations to wrap another API. Doing so lets you build out parts of your GraphQL schema independently of your Keystone lists. You'll need to define the GraphQL types for the output data and, if you have any arguments being passed in, the input types, then write the resolver that calls out to the other API.

Have a look at the graphQL schema extension guide. It describe how to configure Keystone's extendGraphqlSchema option. The Keystone 6 repo has a number of example projects demonstrating schema extension using a variety of GraphQL tooling:

The resolvers themselves can be async, of course. You can call out to remote APIs or use the APIs exposed by the Keystone context object to interact with your database.

Upvotes: 0

Related Questions