question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consider GraphQL for Discovery/Subscription APIs

See original GitHub issue

Overview

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 providers
  • types - search for know events by ce-type
  • search - 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/

Discovery Example

  1. 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"
      }
    ]
  }
}
  1. -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"
          }
        ]
      }
    ]
  }
}
  1. Given a provider and an event type, 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:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jskeetcommented, Jul 22, 2021

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?

0reactions
duglincommented, Jul 28, 2021

Done - created “backlog” label. Let me know if you think other issues should get that label too. I’ll check the recently closed ones

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found