Skip to content

Instantly share code, notes, and snippets.

@alihasan
Created November 2, 2018 10:22
Show Gist options
  • Save alihasan/5bd8b42f55cef3d74c3f549a89365aef to your computer and use it in GitHub Desktop.
Save alihasan/5bd8b42f55cef3d74c3f549a89365aef to your computer and use it in GitHub Desktop.
// apollo-client stuff
const ApolloClient = require('apollo-client').default;
const ApolloInMemoryCache = require('apollo-cache-inmemory').InMemoryCache;
const ApolloHttpLink = require('apollo-link-http').HttpLink;
const gql = require('graphql-tag');
// Node.js does not support ES6 fetch natively
const fetch = require('node-fetch');
const client = new ApolloClient({
link: new ApolloHttpLink({
uri: 'https://api-dev.everydayhealth.com/newsletter/v1/gql',
fetch
}),
cache: new ApolloInMemoryCache()
});
const UPSERT_USER = gql`
mutation UpsertUser($user: UpsertUser) {
upsertUser(user: $user){
id,
email,
newsletters{id, name, rel{ active, source_id, sub_date, unsub_date }},
created_at,
updated_at
}
}
`;
const id = '9999';
const email = `helloali${id}@gmail.com`;
const user = {
id,
email,
newsletters: [
{
id: '25',
rel: {
active: true,
}
},
{
id: '9',
rel: {
active: true,
}
}
]
};
client.mutate({
mutation: UPSERT_USER,
variables: {
user: user
}
})
.then(results => console.log(JSON.stringify(results, null, 2)))
.catch(err => console.log(error));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment