2

Is there a path to follow where you can interface with Azures CosmosDB using GraphQL along with an Azure Functions interface if there needs to be a place where logic is executed.

meds
  • 21,699
  • 37
  • 163
  • 314

3 Answers3

5

I have started on a project Eklee-Azure-Functions-GraphQl to implement a GraphQL interface served by Azure HTTP function(s). It currently supports Azure Cosmos DB SQL API. The GraphQL interface is using graphql-dotnet. It uses a Model-first approach to define and automatically generate your schema. It supports both query and mutation.

David Lee
  • 73
  • 6
  • Can you queries for a subset of the things in one SQL "row" with this approach? Does it still pull the full document from the db? – Jim Aug 13 '20 at 03:47
  • That's the beauty of GraphQL, you query only for the fields you need and internally, the resolver can understand and craft the right SQL query into Cosmos DB. – David Lee Jan 19 '21 at 13:41
1

As far as I know CosmoDB at this time only supports these APIs:

  • Standard SQL
  • MongoDB
  • Cassandra
  • Azure Table
  • Gremlin

If you want to use the GraphQL protocol to query it, you might need to create a wrapper, that translates the GraphQL queries to the appropriate interface.

I would suggest to go for a MongoDB API and implement functions that accept the GraphQL queries and interact with the MongoDB. This should be easy, because MongoDBs queries are looking pretty the same [1].

[1] https://medium.com/the-ideal-system/graphql-and-mongodb-a-quick-example-34643e637e49

markusw
  • 1,975
  • 16
  • 28
  • This would be served well as a comment (pointing out that native GraphQL doesn't exist. As for suggesting a particular API: There's simply no way to suggest a particular API without knowing anything about the OP's data modeling needs. And a particular API doesn't limit the use of GraphQL. – David Makogon Nov 21 '18 at 19:33
  • 1
    Just added the hint, that using MongoDB and a wrapper would be easy to implement. That wouldn't have worked in a comment... – markusw Nov 22 '18 at 05:58
  • The issue with this is, for example with a get query, you still need to pull the full document from the collection and then strip off unwanted fields at the back-end code level. You will still incur latency and RU cost for the entire document json. – Jim Aug 15 '20 at 01:39
0

I've published a demo of using GraphQL backed by the Azure Cosmos SQL API https://github.com/southpolesteve/graphql-cosmos-demo. It could easily be hosted on Azure Functions