Take a look at a live, full-stack application showcasing wasp-graphql.
The Buzz is a social media application that uses both wasp-graphql
and redux-wasp
For an additional feature unique to Redux
while using GraphQL
with Apollo Client v2.0
, check out redux-wasp-apollo
First things first, require Wasp-GraphQL:
import { query } from 'wasp-graphql';
One of our example strings:
let findUser = `query findUser($username: String!){
user(userName: $username) {
id
username
biography
password
address
}
}`;
We set up our endpoint and init:
const API = 'http://localhost:8080/graphql';
const init = {
body: JSON.stringify({
query: queries.findUser,
variables: vars
})
};
Then used Wasp-GraphQL:
query(API, init)
.then(res => {
return res.json();
})
.then(resp => {
store.dispatch(types.updateUser(resp));
});
We incorporated wasp-graphql
into redux-wasp
componentDidMount() {
if (this.props.cookies.cookies.loggedIn) {
const vars = {
username: this.props.cookies.cookies.loggedIn
};
const init = {
body: JSON.stringify({
query: queries.findUser,
variables: vars
})
};
query(API, init)
.then(res => {
return res.json();
})
.then(resp => {
store.dispatch(types.updateUser(resp));
});
}
}
View it here
Thanks goes to these wonderful people (emoji key):
Denny Temple |
Reynolds A Colon |
kamo31 |
marceca |
---|
This project follows the all-contributors specification. Contributions of any kind welcome!
Read our Code of Conduct here.
Free and Open Source under the MIT License.