Skip to content

Commit

Permalink
docs(added documentation): sample usage
Browse files Browse the repository at this point in the history
  • Loading branch information
kennetpostigo committed Nov 16, 2015
1 parent 99f6edf commit caca625
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
28 changes: 22 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,40 @@
It helps you write applications that use tools you are familiar with from the
react ecosystem. react-reach is designed to be used along side redux and react.
React-reach works as the layer that handles communication of data between React
and graphQL.
and graphQL. Reach enables developers to make queries and mutations against GraphQL.

## The need for react-reach
When developing applications with react everything goes smoothly until you begin
to account for request to the server. Usually you would go about making network
request to specified endpoints with REST, or networks request to `"/graphql"`
if you use GraphQL. Now Relay may come to mind, and what makes reach different
is that it only does one thing. So you can use it along Redux.
is that it only does one thing. You can use reach along Redux.
## The Goal
The goal is to make fetching data from a GraphQL server as easy as this:
```javascript
reachGraphQL('localhost:3000/graphql', `
{
//.reachGraphQL() to make a query for some data
//params: reachGraphQL(url, query/mutation, queryParameters)

.reachGraphQL('localhost:1000', `{
user(id: "1") {
name
}
}`);
}`, {})


//.reachWithDispatch() to make a query and dispatch actionCreator passed in
//To be used with redux-thunk or any similar middleware.
//params: reachWithDispatch(url, query/mutation, queryParameters, actionCreator)

.reachWithDispatch('localhost:1000', `{
user(id: "1") {
name
}
}`, {}, somePredefinedActionCreator)


```

## Status on react-reach
I have just began working on react-reach and it is still under development. Stay tuned.
Its now in Beta. Basic Functionality, if you find bugs or if anything isn't working
properly please report it.
9 changes: 8 additions & 1 deletion src/reachGraphQL.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import {transport} from './utils/transport.js';
require("babel-polyfill");

/**
* [reachGraphQL Makes queres or mutations against GraphQL]
* @param {[String]} path [path to the GraphQL server]
* @param {[Object]} query [The query that GraphQL will use to fetch your data]
* @param {[object]} queryParams = {} [should contain object with different query params]
* @return {[Object]} [Data that was queried or qutated]
*/
export function reachGraphQL (path, query, queryParams = {}) {
return async dispatch => {
return async () => {
try{
let response = await transport(path, query, queryParams);
return response.data;
Expand Down
10 changes: 9 additions & 1 deletion src/reachWithDispatch.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import {transport} from './utils/transport.js';
require("babel-polyfill");

/**
* [reachWithDispatch description]
* @param {[String]} path [path to the GraphQL server]
* @param {[Object]} query [The query that GraphQL will use to fetch your data]
* @param {[object]} queryParams = {} [should contain object with different query params]
* @param {[type]} actionCreator = ( [The actionCreator to dispatch]
* @return {[function]} [dispatch to store]
*/
export function reachWithDispatch (path, query, queryParams = {}, actionCreator = () => {}) {
return async dispatch => {
try{
let response = await transport(path, query, queryParams);
dispatch(actionCreator(response.data));
dispatch(actionCreator(response.data));
} catch (error) {
console.log(error)
}
Expand Down

0 comments on commit caca625

Please sign in to comment.