Last active
July 2, 2020 11:13
-
-
Save Addono/eec0aacb75630faf021bdc70af73ca89 to your computer and use it in GitHub Desktop.
Server side Apollo Client usage example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client' | |
// Create GraphQL Client for FaunaDB, replace HttpLink configuration | |
// with your own GraphQL endpoint configuration. | |
const client = new ApolloClient({ | |
cache: new InMemoryCache(), | |
link: new HttpLink({ | |
uri: 'https://graphql.fauna.com/graphql', | |
headers: { | |
"Authorization": `Bearer ${process.env.FAUNADB_SECRET}`, | |
}, | |
}), | |
defaultOptions: { | |
query: { | |
fetchPolicy: 'no-cache', | |
}, | |
} | |
}) | |
// Later, use the client to query our GraphQL endpoint | |
const { data } = await client.query({ | |
query: gql` | |
query GET_USERS { | |
users { | |
name | |
} | |
} | |
`, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment