All Projects → youknowriad → React Graphql Redux

youknowriad / React Graphql Redux

Licence: mit
This library allows you to use GraphQL to query your Redux store

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Graphql Redux

Graphql Kotlin
Libraries for running GraphQL in Kotlin
Stars: ✭ 1,030 (+1960%)
Mutual labels:  graphql
Typeorm Graphql Loader
A query builder to easily resolve nested fields and relations for TypeORM-based GraphQL servers
Stars: ✭ 47 (-6%)
Mutual labels:  graphql
Graphql Query Test Mock
Easily mock GraphQL queries in your Relay Modern / Apollo / any-other-GraphQL-client tests.
Stars: ✭ 49 (-2%)
Mutual labels:  graphql
Graphql Advanced Projection
Fully customizable Mongoose/MongoDB projection generator.
Stars: ✭ 46 (-8%)
Mutual labels:  graphql
Githunt React
[DEPRECATED] 🔃 An example app frontend built with Apollo Client and React
Stars: ✭ 1,036 (+1972%)
Mutual labels:  graphql
Semantic Graphql
Create GraphQL schemas from RDF ontologies
Stars: ✭ 47 (-6%)
Mutual labels:  graphql
Magiql
🌐 💫 Simple and powerful GraphQL Client, love child of react-query ❤️ relay
Stars: ✭ 45 (-10%)
Mutual labels:  graphql
Graphql.el
GraphQL utilities
Stars: ✭ 50 (+0%)
Mutual labels:  graphql
Graphql Scalars
A library of custom GraphQL Scalars for creating precise type-safe GraphQL schemas.
Stars: ✭ 1,023 (+1946%)
Mutual labels:  graphql
Parse Graphql
Parse GraphQL Query.
Stars: ✭ 49 (-2%)
Mutual labels:  graphql
Hunt Android
https://medium.com/@Cuong.Le/open-sourcing-hunt-d49919960ef1
Stars: ✭ 46 (-8%)
Mutual labels:  graphql
Graphql Rails Generators
Graphql Rails Scaffold™. Automatically generate GraphQL types from your rails models.
Stars: ✭ 47 (-6%)
Mutual labels:  graphql
Graphql Zeus
GraphQL client and GraphQL code generator with GraphQL autocomplete library generation ⚡⚡⚡ for browser,nodejs and react native
Stars: ✭ 1,043 (+1986%)
Mutual labels:  graphql
Graphql Retrofit Converter
A Retrofit 2 Converter.Factory for GraphQL.
Stars: ✭ 46 (-8%)
Mutual labels:  graphql
Dropwizard Graphql
Dropwizard GraphQL Bundle
Stars: ✭ 49 (-2%)
Mutual labels:  graphql
Omdb Graphql Wrapper
🚀 GraphQL wrapper for the OMDb API
Stars: ✭ 45 (-10%)
Mutual labels:  graphql
Graphql Kr.github.io
🇰🇷 GraphQL Document in Korean
Stars: ✭ 47 (-6%)
Mutual labels:  graphql
Serverless
This is intended to be a repo containing all of the official AWS Serverless architecture patterns built with CDK for developers to use. All patterns come in Typescript and Python with the exported CloudFormation also included.
Stars: ✭ 1,048 (+1996%)
Mutual labels:  graphql
Appsync Resolvers Example
Example project for AppSync, GraphQL, and AWS Lambda resolvers using Go.
Stars: ✭ 50 (+0%)
Mutual labels:  graphql
Umi Plugin Apollo
Apollo graphql plugin for umi
Stars: ✭ 48 (-4%)
Mutual labels:  graphql

react-graphql-redux

This library allows you to use GraphQL to query your Redux store. This library is in its early stages, feel free to send any PR.

Details about this library in this blog post

Usage

1- Create a GraphQL schema and resolver to match your data:

const createGraph = store => {
	const schema = buildSchema(`
		type Query {
			hello( name: String ): String
		}
	`);

	const root = {
		hello: ({ name }) => `Hello ${name}!`
	};

	return { schema, root };
};

2- Wrap your React Root Component using GraphProvider

import { GraphProvider } from 'react-graphql-redux';

const store = // create your Redux store
const { schema, root } = createGraph( store );

render(
	<GraphProvider store={ store } schema={ schema } root={ root }>
		<App />
	</GraphProvider>
);

3- Start using the query Higher Order Component to provide data as a prop to your components

import { query } from 'react-graphql-redux';

const MyComponent = ({ data }) => {
	return (
		<div>{ data && data.hello }</div>
	);
};

export default query( '{ hello( name: "Riad" ) }' )( MyComponent );

Notice that now, components just declares the data they need without worrying how it's fetched and extracted from the state.

Using Redux Selectors in your Resolvers

In the example above, the function responsible of returning the data : ({ name }) => Hello ${name}! is called a resolver. In this example, it just concats hello with the name arg. But the main purpose of these resolvers will be to retrieve data from the state by calling Redux Selectors.

Say we have a getTodos selector which will retrieve todos from the store. The corresponding resolver could be:

import { getTodos } from './selectors';

const createGraph = store => {
	const schema = buildSchema(`
		type Todo {
			id: Int
			text: String
			done: Boolean
		}

		type Query {
			todos: [Todo]
			// Other root query nodes
		}
	`);

	const root = {
		todos: () => {
			const state = store.getState();
			return getTodos(state);
		}
		// Other resolvers here
	};

	return { schema, root };
};

Fetch Data From the server

Resolvers are also responsible of triggering Redux action creators to fetch the desired data.

For example, if we have afetchTodos action creator we should call to fetch the todos, and we want to refresh this data if it has not been fetched on the last 5 minutes, we could write:

import { refreshWhenExpired } from 'react-graphql-redux';
import { fetchTodos } from './actions';

const createGraph = store => {
	// ....

	const root = {
		todos: () => {
			const timeout =  5 * 60 * 1000;
			const resolverIdentifier = 'fetch-todos';
			refreshWhenExpired(store, resolverIdentifier, {}, timeout, () => {
				store.dispatch(fetchTodos());
			});
			const state = store.getState();
			return getTodos(state);
		}
		// Other resolvers here
	};

// ...

But, to be able to use the refresh helpers provided by the library (like refreshWhenExpired), make sure to include the graphReducer to your store.

import { graphReducer } from 'react-graphql-redux';

const myReduxReducer = combineReducers({
	graphqlResolvers: graphReducer,
	// Add your other reducers here
});

More

  • The query can be computed using component props (use a funciton instead of string for the first query arg)
  • You can use graphql variables in your queries (the second arg of query)
  • If you want to refresh the data on each new query used, it's possible
  • You can use GraphiQL to test/explore your graph
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].