Consider GraphQL for Discovery/Subscription APIs
See original GitHub issueOverview
As part of the design exercise for the discovery and subscription APIs, it was suggested that we consider GraphQL instead of REST.
To start the conversation, I’ve put together a candidate design for what a GraphQL API would look like.
You can see it in action here: discovery.in-the-cloud.dev
There this provides for essentially 3 entry points for discover in the RootQueryType
providers
- Search for human readable providerstypes
- search for know events by ce-typesearch
- open search against providers and types
This leads to other queries that narrow in on information to actually get the information needed to create a subscription.
producer(provider:, type: )
Reasons to choose GraphQL
- Flexibility for representing the relationships we have
- provider <-> type
- {provider, type} -> producer
- allows for easy future expansion if we wanted to introduce
source
discovery (ce-source) - Sever libraries available in many languages: https://graphql.org/code/
- Client libraries available: https://graphql.org/code/#graphql-clients
Discovery Example
- What providers to I have?
{
providers{
name
}
}
which produces the results
{
"data": {
"providers": [
{
"name": "Cloud Storage"
},
{
"name": "Cloud SQL Database"
},
{
"name": "IOT Broker"
},
{
"name": "GitHub"
},
{
"name": "Other Cloud Storage"
},
{
"name": "Cloud Pub/Sub System"
}
]
}
}
- -or- perhaps I want to also see the event types available, and also narrow the providers down to things with “storage” in the name
{
providers(matching: "storage") {
name
description
types {
name
}
}
}
Which would produce the results of
{
"data": {
"providers": [
{
"description": "Cloud Blob Storage",
"name": "Cloud Storage",
"types": [
{
"name": "com.storage.object.create"
},
{
"name": "com.storage.object.delete"
}
]
},
{
"description": "A differe cloud blob storage",
"name": "Other Cloud Storage",
"types": [
{
"name": "com.storage.object.create"
},
{
"name": "com.storage.object.delete"
}
]
}
]
}
}
- Given a
provider
and an eventtype
, it is possible to narrow down into the details needed to create a subscription.
{
producer(provider: "Cloud Storage", type: "com.storage.object.create") {
dataSchema
dataContentType
subscriptionConfig {
name
}
subscriptionEndpoint
protocols
}
}
which produces the results of
{
"data": {
"producer": [
{
"dataContentType": "application/json",
"dataSchema": "https://schemas.in-the-cloud.dev/download/com.storage.object.create.json",
"protocols": [
"http"
],
"subscriptionConfig": [
{
"name": "path"
}
],
"subscriptionEndpoint": "https://subscribe.events.broker/com.storage.object.create?provider=Cloud Storage"
}
]
}
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:10 (6 by maintainers)
Top Results From Across the Web
GraphQL vs. REST
Often, GraphQL is presented as a revolutionary new way to think about APIs. Instead of working with rigid server-defined endpoints, ...
Read more >GraphQL Best Practices
Why do most APIs version? When there's limited control over the data that's returned from an API endpoint, any change can be considered...
Read more >GraphQL vs. REST APIs: Why you shouldn't use GraphQL
When should you use a REST API? Now that we've outlined some use cases that call for using GraphQL, let's discuss some reasons...
Read more >Interacting with APIs: REST and GraphQL | Google Cloud Blog
Think of APIs as digital products that let enterprises take their assets and, in order to increase the leverage of those assets, put...
Read more >Decision Guide to GraphQL Implementation - AWS
We then walk through what to consider when implementing a GraphQL API and whether you should host your own GraphQL server or choose...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We’ve had a few items like this where we think they’re worth keeping track of but without keeping them open. Perhaps create a “backlog” label, apply that, then close?
Done - created “backlog” label. Let me know if you think other issues should get that label too. I’ll check the recently closed ones