Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass variables($input) to fields written within getSubscription? #30

Open
sidutta opened this issue Apr 7, 2017 · 2 comments
Open

Comments

@sidutta
Copy link

sidutta commented Apr 7, 2017

My components have query fragments of the following form:

initialVariables : {
	type : 'videos',
	pageSize : 10,
	community : 3
},
fragments: {
	viewer: () => Relay.QL`
		fragment on Viewer {
			id,
			newItemsAvailable(type : $type, community : $community),
			newsFeedItems(first : $pageSize, type : $type, community : $community) {
				pageInfo {
					hasNextPage
				},
				edges {
					cursor,
					node {
						...
					}
				}
			}
		}
	`
},

I want to subscribe to changes in the field newItemsAvailable. To do so I would need the following getSubscription function:

getSubscription() {
  return Relay.QL`
    subscription {
      newsFeedItemsAvailableSubscription(input: $input) {
        viewer {
          newItemsAvailable(type : $type, community : $community)
        }
      }
    }
  `;
}

I can't omit (type : $type, community : $community) from here since that would give an error. In the worst case I would have to send dummy hardcoded values.
I guess

subscriptions: [
    ({ viewer, type, community }) => new NewsFeedItemsAvailableSubscription({ viewer, type, community }),
  ]

and

getVariables() {
  return {
    id: this.props.viewer.id,
    type: this.props.type,
    community: this.props.community
  };
}

feed the values of type and community into $input through ...subscription.getVariables(). However, how can I make them available in newItemsAvailable(type : $type, community : $community). I haven't looked into the source code of Relay so have no clue of how all this generally works.

@sidutta
Copy link
Author

sidutta commented Apr 7, 2017

If the above isn't possible(using data from $input next to subfields), I feel the above snippets are sufficient to get an understanding of what I am trying to do here. What solution do you suggest? ${input.type} gives an error(Error: You supplied a GraphQL document that uses template substitution for an argument value, but variable substitution has not been enabled.) too. Does Relay store fields fetched using separate variables separately? If so, I think it makes sense to subscribe multiple times on the same field using different variables.

@sidutta
Copy link
Author

sidutta commented Apr 7, 2017

Since subscriptions are based on mutations, facebook/relay#1046 seems relevant. Especially the comment by nodkz on the "new Mutation API".

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

No branches or pull requests

1 participant