GraphQL to Blaze/React


#1

Has anyone tried and succeded in making a GraphQL query from a React component that lives inside a Blaze template using Apollo Cient or Boost (either one)?

I’m slowly migrating my Blaze templates over to React using react-template-helper and it’s working out great. I’m currently using the lib react-meteor-data, and its function withTracker to query Mini Mongo and pull the data in as I did with my Blaze templates.

So far, so good.

I created a Apollo GraphQL server and would like to query it from these new React components as I would do in a Regular React project.

I’m using swydo:blaze-apollo to connect the ApolloClient to Blaze

This works, I can do:

import gql from 'graphql-tag';

Template.templateName.onCreated(function() {
	const allCustomers = gql`
		{
			customers {
				email
				name
				age
				id
			}
		}
	`;

	const result = this.gqlQuery({ query: allCustomers }).get();

	console.warn(JSON.stringify(result));
});

And eventuall get the correct result. Maybe here I can pipe this data into the React component via a callback.

But even better, how do I get the data directly inside the React component?

Any help is appriciated.

Thanks!