Graphene: Apollo Optics Integration

Created on 25 May 2017  路  34Comments  路  Source: graphql-python/graphene

Apollo just started rolling out optics free teir, and are offering for different languages.

I will be looking into how possibly to integrate this into our app, but would love any pointers on where to start.

Relevant documentation

wontfix

Most helpful comment

Ok so I haven't had time to complete it in the past few days but I'm sharing the work that has already been done. I hope I'll be able to get to it this week but anyone who wants to help is welcome :)

graphql-server-core
https://github.com/ekampf/graphql-server-core/tree/feature/tracing

TracingMiddleware is where we implement the collection of the tracing data that we later need to expose somewhere in the run_http_query flow...

All 34 comments

Hi @chaffeqa!

I think creating an Optics client for Graphene would be a great move for @apollographql as few more people already asked for that.

The easiest way would be doing the integration using a custom middleware for it.

Curious to know if this in your plans? @helfer @stubailo

Right now we aren't actively working on Graphene integration but we provide advice and support for people working on new agents, for example there is one currently being worked on for Sangria. Looks like you're ahead of the game @chaffeqa, since you've found the correct repository. I'll ping people on Slack to get in touch and pass along any more resources we have!

Hey guys,

Any progress on this? Is there anything I can do to help?

none here :( sorry been deep in integrating apollo w next.js 馃帀

I'd suggest joining the Apollo slack and messaging me there, we have a channel to help people build agents.

Maybe I'm missing something but it doesn't seem like whats in https://github.com/apollographql/optics-agent should make sense outside the Apollo team...
It would be great if there was a rough "Quickstart" on the guidelines for a new agent...

Given the recent interest (here and offline), I'm thinking to create an open-source GraphQL logging tool with an easy integration with Graphene or any other GraphQL framework.
(similar business model as Sentry).

Will some of you be open to pay half of the price as apollo optics while having a similar interface?

regardless of what my company says, we will gladly pay for that!

I've honestly been looking for ways to contribute to both graphene and apollo personally, its making huge wins for our company and my personal sanity 馃槈

@syrusakbary I'd be happy to help build it.

@chaffeqa, I think @martijnwalraven is the person to talk to to help build out an Optics integration! We're dedicated to making sure the pricing works for people at all scales. The new free tier is just the first step, we want to make sure everyone who wants to get insight into their GraphQL API can do that.

We have some ideas also about how we can work towards a more standard way for GraphQL servers to report performance data so you can send data to optics or any other service in an easy way that all servers can support. So if anyone is interested in that let's set up a hangout sometime soon?

Great idea! Count me in. You can reach me or hangout me at [email protected]

(east coast... cuz timezones /shrug)

@chaffeqa: Great! I'll ping a few more people and we can try to set up a meeting for next week.

I'm interested in helping make a graphene-optics-agent client a reality!

I'll try joining the Apollo slack team to make myself a little more reachable.

@syrusakbary @chaffeqa @ajhyndman: I'm sorry I'm only getting back to you now, but I just published a description of Apollo Tracing, a proposed tracing format for GraphQL that will allow all GraphQL servers to report data to Optics. Would be great to get your feedback and see how we can add support for this to Graphene!

So I'm 99% done integrating Apollo Tracing into Graphene.
The code is actually in graphql-core (See https://github.com/graphql-python/graphql-core/pull/148) and graphql-server-core where the code middleware doing the tracing and adding the data is (PR as soon as the relevant graphql-core changes get merged)

@ekampf It looks like graphql-python/graphql-core#148 was merged ~15 days ago. Any update on the remaining changes for graphql-server-core and graphene?

@dvndrsn I kinda stopped working on it waiting for that PR to merge.
Will try and find time to complete this feature ASAP...

Thanks sir! We're pretty excited for this feature, please let us know if there's anything we can do to help!

Any news on this ?

@chaffeqa @ekampf This seems like a great feature to have. Hope we can have it soon!

@ekampf I'm eager to hook up Optics. What can I do to help push this over the finish line? My company would gladly make a monetary contribution and I can contribute some code if you point me in the right direction.

Sorry I didnt have the time to work on it latelly... I will try to finish everything and push some code this weekend.
Will need help testing it :)

I will update here ASAP

Ok so I haven't had time to complete it in the past few days but I'm sharing the work that has already been done. I hope I'll be able to get to it this week but anyone who wants to help is welcome :)

graphql-server-core
https://github.com/ekampf/graphql-server-core/tree/feature/tracing

TracingMiddleware is where we implement the collection of the tracing data that we later need to expose somewhere in the run_http_query flow...

So this has been a long awaited update...
I have updated https://github.com/ekampf/graphql-server-core/tree/feature/tracing to match the spec (use nanoseconds) and support Python 3.7.

I'm going to do some testing with Apollo to make sure this works this weeks.
However, I think the right place for the TracingMiddleware would be graphql-core - this way we could also instrument the parsing & validation phases.

So I will do some more testing and then move the code there.

@syrusakbary any thoughts?

Here is the initial code in graphql-core - https://github.com/ekampf/graphql-core/tree/feature/tracing

If anyone subscribed here can help test this against Apollo Engine and provide feedback that would be much appreciated

Thank you @ekampf for your work! Can you explain how to use TracingMiddleware please?
I tried to use it with graphene-django, but I am not able to make it work. It may not be compatible yet?

I tried this in settings.py:

GRAPHENE = {
    'SCHEMA': 'path.to.schema',
    'MIDDLEWARE': [
        'graphql.execution.tracing.TracingMiddleware',
    ]
}
[...]
  File "/usr/local/lib/python3.6/site-packages/graphene_django/views.py", line 48, in instantiate_middleware
    yield middleware()
TypeError: __init__() missing 1 required positional argument: 'enabled'



md5-e126b888aa7c04a27491099d8853ad07



[...]
File "/usr/local/lib/python3.6/site-packages/graphql/execution/tracing.py", line 96, in resolve
"startOffset": self.now() - self.start_time,
TypeError: unsupported operand type(s) for -: 'int' and 'NoneType'
```

@Prince-Leto you dont use it directly but rather call set_default_backend(GraphQLCoreBackend(tracing=True)) before initializing GraphQLView

The reason is its not a pure middleware - it has a middleware part to trace all the resolvers, but it also has part that has to ruin in backend itself to measure parsing and validating the query (before resolvers start to run)

Given the recent interest (here and offline), I'm thinking to create an open-source GraphQL logging tool with an easy integration with Graphene or any other GraphQL framework.
(similar business model as Sentry).

Will some of you be open to pay half of the price as apollo optics while having a similar interface?

I'd be happy to contribute! Is there a Slack channel that I could join?

@helpse you can find me at the #graphene channel at the GraphQL slack

I'd like to get involved in this. What is the status?

@ekampf any word on this?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@ekampf did you decide to abandon this?

Was this page helpful?
0 / 5 - 0 ratings