graphql-hive / graphql-hive/SOFA

Overriding path to support multiple methods on the same /resource

Open
#51 9 comments 2 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1.1k
Forks
91
Avg merge
5h 10m
Merged PRs (30d)
1

Description

Thanks for creating this library, very nice idea!

I'm trying to support both `GET` and `HEAD` for the same resource, for example `"foobar"`, mounted on `/foobar` path. The v0.4.0 release with HTTP method customization comes in handy.

I'm trying to expose the following HTTP routes:
* use `HEAD /foobar`, semantically, to check for existence/absence of a given resource, and return respectively code `200` and `404` (empty body)
* use `GET /foobar` to fully retrieve the content of that resource, returning a `200` + body in case of existence, and a `404` if missing

I use two GraphQL queries defined as `foobar()` and `foobarExists()`, respectively, in my GraphQL schema. I need to override the path mounted in express as `/foobar` instead of `/foobar-exists`.

At the moment, I simply strip the `-exists` part of the path (`@directive()` would be cleaner, rather than using a convention in the `path`/GraphQL query name). However this approach with current version of SOFA only seems to update the path in the swagger document, but does not override the path in the `express.Router` instance. By looking at SOFA's code, my understanding is that this cannot be supported at the moment unless manually updating the `express.Router` instance returned by `useSofa()`.

In short, I'm trying to expose multiple GraphQL queries on the same `/resource` path, semantically distinguishing actions via HTTP methods.
What would you recommend for such use case?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at useSofa() and the Express Router registration, then compare how the overridden path is represented in the Swagger document with how routes are mounted. The change is done when multiple GraphQL queries can use the same /foobar path with distinct GET and HEAD methods while preserving the described 200 and 404 responses.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, openapi, typescript
Domain
api, backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.