I would like to use a GraphQL API on a React-Native App with react-apollo.
My server-side API is functional. All my tests with the playground works perfectly.
On the other hand, since react-native things get complicated: how to reuse what was set up server side? (mutation in particular) Do I have to duplicate the GraphQL code?
I exported my schema graphql using CodeGen (great tool!), But how to use it on react-native ?
My config on React-Native :
const httpLink = createHttpLink({
uri: API_GRAPHQL_URL,
clientState: {
typeDefs
}
});
const getToken = async () => await AsyncStorage.getItem('userToken');
const authLink = setContext(async (_, { headers }) => {
const token = await getToken();
return {
headers: {
...headers,
authorization: token ? `Bearer ${token}` : ''
}
};
});
const client = new ApolloClient({
link: authLink.concat(httpLink),
cache: new InMemoryCache()
});
My typeDefs is schema exported on CodeGen, for example :
But, how use Mutation with my exported configuration ? I use react-apollo-hooks
.
The client part of GraphQL is not very clear for me, despite a great reaction-apollo documentation.
Would anyone help me or have a reference article on the subject?
Thank you so much !