Relay: [Modern] relay-compiler barfs at the word "subscription"

Created on 29 Apr 2017  路  9Comments  路  Source: facebook/relay

Using the todo-modern example app to reproduce (with a subscription set up on the server identical to the query):

query={graphql`
      subscription appQuery {
        viewer {
          ...TodoApp_viewer
        }
      }
    `}

results in:

Writing default
Error: Expected null to be a GraphQL composite type.

When I try it out on graphiql, it returns just fine.
I'd love to see a more helpful error (and support for the word subscription 馃槃 )

Most helpful comment

All 9 comments

Thanks for reporting. It looks like the compiler is assuming that a type exists in your schema but the value is null. What does the root of your schema look like? Does it define a Subscription type? Note that subscription <name> ... is semantically different than query <name> ..., and that these correspond to different root types in the schema. Also note that QueryRenderer (which it appears you're using) accepts queries, not subscriptions. Take a look at RelayModernEnvironment for executing a subscription.

To reproduce, I modified the schema as follows (in todo-modern):

const Subscription = new GraphQLObjectType({
  name: 'Subscription',
  fields: {
    viewer: {
      type: GraphQLUser,
      resolve: () => getViewer(),
    },
    node: nodeField,
  },
});

export const schema = new GraphQLSchema({
  query: Query,
  mutation: Mutation,
  subscription: Subscription
});

After playing around with the 2nd param of Network.create, sendSubscription, requestSubscription I figured I was probably doing subs wrong, but I figured a better error in that spot might be good for when i inevitably make a typo in the root query & wonder which root query caused it.

@josephsavona Is there any document for how to get subscription working besides following the todo-modern example? Thanks.

@mattkrick Hey! Did you end up successfully getting the subscription to work? If so how? Could you maybe post the code to your query renderer?

yeah, but it it ain't pretty :see_no_evil: with the goal of not releasing antipatterns into the wild, i'll keep it private for now, hopefully the relay folks give us an example or some docs soon :grinning:

Ah okay! I'll be keeping an eye out for these docs 馃憖 In the meantime I'm not too sure what todo with the subscriptions 馃

oh that's _good_. i can see it now: updater + CmRDT payload + Draft.js = google docs

closing to keep issues clean

Was this page helpful?
0 / 5 - 0 ratings