Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Exclude subscription type when augmenting queries #323

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Exclude subscription type when augmenting queries #323

wants to merge 1 commit into from

Conversation

viktorstrate
Copy link

Subscriptions are not yet supported, but it is still possible to implement it manually, see #164 (comment)

I tried to do this for a personal project, and was met with the following error message:

Error: Unknown type "_SubscriptionFilter". Did you mean "Subscription", "_SubscriptionOrdering", "_UserFilter", "_ShareTokenFilter", or "_SiteInfoFilter"?
    at assertValidSDL (/Users/viktorstrate/Development/photoview/api/node_modules/graphql/validation/validate.js:108:11)
    at Object.buildASTSchema (/Users/viktorstrate/Development/photoview/api/node_modules/graphql/utilities/buildASTSchema.js:71:34)
    at Object.buildSchemaFromTypeDefinitions (/Users/viktorstrate/Development/photoview/api/node_modules/graphql-tools/dist/generate/buildSchemaFromTypeDefinitions.js:23:28)
    at makeExecutableSchema (/Users/viktorstrate/Development/photoview/api/node_modules/graphql-tools/dist/makeExecutableSchema.js:26:29)
    at makeAugmentedExecutableSchema (/Users/viktorstrate/Development/photoview/api/node_modules/neo4j-graphql-js/dist/augment.js:82:49)
    at makeAugmentedSchema (/Users/viktorstrate/Development/photoview/api/node_modules/neo4j-graphql-js/dist/index.js:229:53)
    at Object.<anonymous> (/Users/viktorstrate/Development/photoview/api/build/graphql-schema.js:61:54)

The problem is that the Subscription type is interpreted by the augmentResolver as a generic type, like Post in the example below.

const typeDefs = gql`
  type Subscription {
    postAdded: Post 
  }
  
  type Query {
    posts: [Post]
  }

  type Mutation {
    addPost(author: String, comment: String): Post
  }

  type Post {
    author: String
    comment: String
  }
`

A quick fix was to exclude Subscription in the config, like so:

const schema = makeAugmentedSchema({
  typeDefs,
  config: {
    query: {
      exclude: ['Subscription'],
    },
  },
})

But this shouldn't really be necessary, since Subscription is a special type, like Query and Mutation.

And this pull request, just automatically excludes subscription types, until subscriptions are properly implemented, for those who want to implement subscriptions manually.

@codecov-io
Copy link

codecov-io commented Oct 15, 2019

Codecov Report

Merging #323 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #323      +/-   ##
=========================================
+ Coverage    95.4%   95.4%   +<.01%     
=========================================
  Files          10      10              
  Lines        2350    2351       +1     
=========================================
+ Hits         2242    2243       +1     
  Misses        108     108
Impacted Files Coverage Δ
src/utils.js 93.23% <100%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 70e6966...897dea3. Read the comment docs.

@johnymontana
Copy link
Contributor

Hey @viktorstrate - thanks for the PR!

This behavior should now be fixed in the v2.8.0 release. I'll add a test to verify specifically for the Subscription type, but in the meantime would you mind testing the release and see if it works for you?

@viktorstrate
Copy link
Author

@johnymontana
This was also just a temporary fix, so it is great to see that a better solution has already been made. 👍

@michaeldgraham
Copy link
Collaborator

#608

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants