import { gql } from "apollo-boost";
// or you can use `import gql from 'graphql-tag';` instead
...
client
.query({
query: gql`
{
rates(currency: "USD") {
currency
}
}
`
})
.then(result => console.log(result));
import ApolloClient from "apollo-boost";
const client = new ApolloClient({
uri: "https://w5xlvm3vzz.lp.gql.zone/graphql"
});
import { Accounts } from 'meteor/accounts-base'
import ApolloClient from 'apollo-boost'
const client = new ApolloClient({
uri: '/graphql',
request: operation =>
operation.setContext(() => ({
headers: {
authorization: Accounts._storedLoginToken()
}
}))
})
import ApolloClient from 'apollo-boost'
const client = new ApolloClient({
request: (operation) => {
const token = localStorage.getItem('token')
operation.setContext({
headers: {
authorization: token ? `Bearer ${token}` : ''
}
})
}
})
const { ApolloServer, gql } = require('apollo-server');
// Hardcoded data store
const books = [
{
title: 'The Awakening',
author: 'Kate Chopin',
},
{
title: 'City of Glass',
author: 'Paul Auster',
},
];
// Schema definition
const typeDefs = gql`
type Book {
title: String
author: String
}
type Query {
books: [Book]
}
`;
// Resolver map
const resolvers = {
Query: {
books() {
return books;
}
},
};
// Pass schema definition and resolvers to the
// ApolloServer constructor
const server = new ApolloServer({ typeDefs, resolvers });
// Launch the server
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});