Skip to content

Commit 2ebb0c5

Browse files
authored
Update getting started doc to use vite (#11352)
1 parent 68166a2 commit 2ebb0c5

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

docs/source/data/queries.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The `useQuery` [React hook](https://react.dev/reference/react) is the primary AP
2424
2525
Let's look at an example. First, we'll create a GraphQL query named `GET_DOGS`. Remember to wrap query strings in the `gql` function to parse them into query documents:
2626

27-
```jsx title="index.js"
27+
```js title="index.js"
2828
import { gql, useQuery } from '@apollo/client';
2929

3030
const GET_DOGS = gql`

docs/source/get-started.mdx

+13-13
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Hello! 👋 This short tutorial gets you up and running with Apollo Client.
1010

1111
To start this tutorial, do one of the following:
1212

13-
- Create a new React project locally with [Create React App](https://create-react-app.dev/), or
13+
- Create a new React project locally with [Vite](https://vitejs.dev/), or
1414
- Create a new React sandbox on [CodeSandbox](https://codesandbox.io/).
1515

1616
## Step 2: Install dependencies
@@ -34,15 +34,15 @@ Our example application will use the [FlyBy GraphQL API](https://flyby-router-de
3434

3535
With our dependencies set up, we can now initialize an `ApolloClient` instance.
3636

37-
In `index.js`, let's first import the symbols we need from `@apollo/client`:
37+
In `main.jsx`, let's first import the symbols we need from `@apollo/client`:
3838

39-
```js title="index.js"
39+
```jsx title="main.jsx"
4040
import { ApolloClient, InMemoryCache, ApolloProvider, gql } from '@apollo/client';
4141
```
4242

4343
Next we'll initialize `ApolloClient`, passing its constructor a configuration object with the `uri` and `cache` fields:
4444

45-
```js title="index.js"
45+
```jsx title="main.jsx"
4646
const client = new ApolloClient({
4747
uri: 'https://flyby-router-demo.herokuapp.com/',
4848
cache: new InMemoryCache(),
@@ -54,9 +54,9 @@ const client = new ApolloClient({
5454

5555
That's it! Our `client` is ready to start fetching data. Now before we start using Apollo Client with React, let's first try sending a query with plain JavaScript.
5656

57-
In the same `index.js` file, call `client.query()` with the query string (wrapped in the `gql` template literal) shown below:
57+
In the same `main.jsx` file, call `client.query()` with the query string (wrapped in the `gql` template literal) shown below:
5858

59-
```js title="index.js"
59+
```jsx title="main.jsx"
6060
// const client = ...
6161

6262
client
@@ -85,9 +85,9 @@ Let's look at how that works!
8585

8686
You connect Apollo Client to React with the `ApolloProvider` component. Similar to React's [`Context.Provider`](https://react.dev/reference/react/useContext), `ApolloProvider` wraps your React app and places Apollo Client on the context, enabling you to access it from anywhere in your component tree.
8787

88-
In `index.js`, let's wrap our React app with an `ApolloProvider`. We suggest putting the `ApolloProvider` somewhere high in your app, above any component that might need to access GraphQL data.
88+
In `main.jsx`, let's wrap our React app with an `ApolloProvider`. We suggest putting the `ApolloProvider` somewhere high in your app, above any component that might need to access GraphQL data.
8989

90-
```jsx title="index.js" {15-17}
90+
```jsx title="main.jsx" {15-17}
9191
import React from 'react';
9292
import * as ReactDOM from 'react-dom/client';
9393
import { ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client';
@@ -112,9 +112,9 @@ root.render(
112112

113113
After your `ApolloProvider` is hooked up, you can start requesting data with `useQuery`. The `useQuery` hook is a [React hook](https://react.dev/reference/react) that shares GraphQL data with your UI.
114114

115-
Switching over to our `App.js` file, we'll start by replacing our existing file contents with the code snippet below:
115+
Switching over to our `App.jsx` file, we'll start by replacing our existing file contents with the code snippet below:
116116

117-
```js title="App.js"
117+
```jsx title="App.jsx"
118118
// Import everything needed to use the `useQuery` hook
119119
import { useQuery, gql } from '@apollo/client';
120120

@@ -129,7 +129,7 @@ export default function App() {
129129

130130
We can define the query we want to execute by wrapping it in the `gql` template literal:
131131

132-
```js title="App.js"
132+
```jsx title="App.jsx"
133133
const GET_LOCATIONS = gql`
134134
query GetLocations {
135135
locations {
@@ -144,7 +144,7 @@ const GET_LOCATIONS = gql`
144144

145145
Next, let's define a component named `DisplayLocations` that executes our `GET_LOCATIONS` query with the `useQuery` hook:
146146

147-
```js title="App.js" {2}
147+
```jsx title="App.jsx" {2}
148148
function DisplayLocations() {
149149
const { loading, error, data } = useQuery(GET_LOCATIONS);
150150

@@ -171,7 +171,7 @@ Whenever this component renders, the `useQuery` hook automatically executes our
171171

172172
Finally, we'll add `DisplayLocations` to our existing component tree:
173173

174-
```jsx title="App.js" {6}
174+
```jsx title="App.jsx" {6}
175175
export default function App() {
176176
return (
177177
<div>

0 commit comments

Comments
 (0)