You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Get started with SQLite Cloud using Apollo and GraphQL.
4
+
category: getting-started
5
+
status: publish
6
+
slug: quick-start-apollo-graphql
7
+
---
8
+
9
+
In this quickstart, we will show you how to get started with SQLite Cloud and Apollo/GraphQL by writing a simple GraphQL wrapper around a SQLite Cloud database connection.
10
+
11
+
1.**Set up a SQLite Cloud account**
12
+
- If you haven't already, [sign up for a SQLite Cloud account](https://sqlitecloud.io/register) and create a new project.
13
+
- In this guide, we will use the sample datasets that come pre-loaded with SQLite Cloud.
14
+
15
+
2.**Install the necessary dependencies**
16
+
- In your terminal run the following commands to install a new Apollo Server app.
17
+
18
+
```bash
19
+
mkdir sqlc-quickstart
20
+
cd sqlc-quickstart
21
+
npm install apollo-server graphql
22
+
```
23
+
24
+
3.**Create a new Apollo Server app**
25
+
- Create a new file called `server.js` and add the following code.
constres=awaitdb.sql`SELECT * FROM artists WHERE Name LIKE ${name};`;
114
+
if (res.length===0) returnnull;
115
+
return res[0];
116
+
},
117
+
albumsByArtist:async (_, { artistId }) => {
118
+
returnawaitdb.sql`SELECT albums.AlbumId, albums.Title FROM albums INNER JOIN artists ON albums.ArtistId = artists.ArtistId WHERE artists.ArtistId = ${artistId}`;
119
+
},
120
+
},
121
+
Mutation: {
122
+
createArtist:async (_, { name }) => {
123
+
constres=
124
+
awaitdb.sql`INSERT INTO artists (Name) VALUES (${name})`;
125
+
if (res.changes===0) returnnull;
126
+
return { ArtistId:res.lastID, Name: name };
127
+
},
128
+
createAlbum:async (_, { title, artistId }) => {
129
+
constres=
130
+
awaitdb.sql`INSERT INTO albums (Title, ArtistId) VALUES (${title}, ${artistId})`;
131
+
if (res.changes===0) returnnull;
132
+
return {
133
+
AlbumId:res.lastID,
134
+
Title: title,
135
+
ArtistId: artistId,
136
+
};
137
+
},
138
+
},
139
+
};
140
+
```
141
+
142
+
- Lastly, pass the GraphQLL type definitions and resolvers into a new ApolloServer instance, and start the server.
- In your terminal, run the following command to start your Apollo Server.
156
+
```bash
157
+
node server.js
158
+
```
159
+
160
+
5.**Query your data**
161
+
- Open your browser and navigate to `http://localhost:4000` to access the Apollo GraphQL Playground.
162
+
- Use the following queries to interact with your SQLite Cloud database.
163
+
164
+
Read operation:
165
+
```graphql
166
+
query {
167
+
albums {
168
+
AlbumId
169
+
Title
170
+
ArtistId
171
+
}
172
+
}
173
+
```
174
+
175
+
Write operation:
176
+
```graphql
177
+
mutation {
178
+
createArtist(name: "New Artist") {
179
+
ArtistId
180
+
Name
181
+
}
182
+
}
183
+
```
184
+
185
+
And that's it! You've successfully built an Apollo/GraphQL server that reads and writes data to a SQLite Cloud database.
186
+
187
+
For the full code example, see the [SQLite Cloud Apollo/GraphQL example repo](https://github.com/sqlitecloud/examples/tree/main/graphql-apollo/server).
Copy file name to clipboardExpand all lines: sqlite-cloud/quick-start-django.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ slug: quick-start-django
9
9
In this quickstart, we will show you how to get started with SQLite Cloud and Django by building a simple application that connects to and reads from a SQLite Cloud database.
10
10
11
11
1.**Set up a SQLite Cloud account**
12
-
- If you haven't already, [sign up for a SQLite Cloud account](https://sqlitecloud.io/register) and create a new database.
12
+
- If you haven't already, [sign up for a SQLite Cloud account](https://sqlitecloud.io/register) and create a new project.
13
13
- In this guide, we will use the sample datasets that come pre-loaded with SQLite Cloud.
Copy file name to clipboardExpand all lines: sqlite-cloud/quick-start-next.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ In this quickstart, we will show you how to get started with SQLite Cloud and Ne
11
11
---
12
12
13
13
1.**Set up a SQLite Cloud account**
14
-
- If you haven't already, [sign up for a SQLite Cloud account](https://sqlitecloud.io/register) and create a new database.
14
+
- If you haven't already, [sign up for a SQLite Cloud account](https://sqlitecloud.io/register) and create a new project.
15
15
- In this guide, we will use the sample datasets that come pre-loaded with SQLite Cloud.
16
16
2.**Create a Next.js app**
17
17
- Create a Next app using ```create-next-app```. The following command creates a very simple app (JS, no Tailwind, uses the latest App Router) to keep the focus on querying the data.
Copy file name to clipboardExpand all lines: sqlite-cloud/quick-start-prisma.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ In this quickstart, we will show you how to get started with SQLite Cloud and Pr
11
11
---
12
12
13
13
1.**Set up a SQLite Cloud account**
14
-
- If you haven't already, [sign up for a SQLite Cloud account](https://sqlitecloud.io/register) and create a new database.
14
+
- If you haven't already, [sign up for a SQLite Cloud account](https://sqlitecloud.io/register) and create a new project.
15
15
- In this guide, we will use the sample datasets that come pre-loaded with SQLite Cloud.
16
16
2.**Create a Next.js app**
17
17
- Create a Next app using ```create-next-app```. The following command creates a very simple app (JS, no Tailwind, uses the latest App Router) to keep the focus on querying the data.
0 commit comments