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.

Please make subscription value structure consistent with query value structure

See original GitHub issue

So imagine the following basic schema:

type Query {
  foo(tag: String): MetadataItem
}

type Subscription {
  foo(tag: String): MetadataItem
}

My resolver for Query.foo can return a Promise<MetadataItem>. You would think my subscribe resolver could return an AsyncIterable<MetadataItem>. But noooo… For whatever reason it has to return an AsyncIterable<{foo: MetadataItem}>. Why do I have to wrap the values I yield in an object? Is there a good reason for this or is it just a mistake?

This is really annoying and it always trips me up. Why were subscriptions designed this way instead of being more consistent with queries? I feel very angry about how often I have had to debug issues stemming from this, because it’s just not an intuitive inconsistency. It’s very easy to forget about.

GraphQL could so easily wrap the values I yield in an object with the field name, the only reason I can imagine that it doesn’t is some performance nitpick.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
IvanGoncharovcommented, Jul 26, 2018

@jedwards1211 It’s actually very consistent with query if you have the right mental model. You yield root value for the entire query (not just for foo field) and then it executing exactly the same as a query: http://facebook.github.io/graphql/June2018/#ExecuteSubscriptionEvent()

Actually, it’s so consistent with a query that if you register resolve on Subscription.foo it would be called with the value you yielded from your stream.

0reactions
jedwards1211commented, Mar 25, 2020

@IvanGoncharov I still find this terribly confusing.

Although this doesn’t seem to the behavior described in the spec, from what I’m observing with running code, it appears that:

  • If subscribe has a sibling resolve function, then subscribe can yield just the value of its field without any wrapper object?
  • Otherwise subscribe has to yield an object corresponding to the shape of the Subscription type

I am using Apollo’s buildExecutableSchema so maybe the confusion’s coming from there…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Subscriptions and Live Queries - Real Time with GraphQL
Let's take a quick look at the graphql-js reference implementation! Since promises cannot represent multiple values over time, the graphql-js ...
Read more >
Query Structure - Ads API - Google Developers
To construct a query in Google Ads Query Language, you will need to build it using ... segment fields, and metrics, returning the...
Read more >
5 Subscription-Based Pricing Models, and How to Choose the ...
Get an overview of subscription-based pricing models and how to choose the one that'll work best for your business.
Read more >
Using CloudWatch Logs subscription filters
The subscription filter delivers every logged activity made by "Root" AWS credentials to a Kinesis stream called "RootAccess." For more information about how...
Read more >
Query Processing Architecture Guide - SQL Server
The expression @d+1 isn't constant-folded, because @d is a parameter. However, at optimization time, the value of the parameter is known. This ...
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