Skip to content

Commit f21b353

Browse files
committed
Move GraphQL queries to separate files
1 parent fd8cdef commit f21b353

10 files changed

+172
-170
lines changed

codegen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
overwrite: true
22
schema: "http://localhost:4000"
3-
documents: "src/**/*.tsx"
3+
documents: "src/**/*.graphql"
44
generates:
55
src/generated/graphql.tsx:
66
plugins:

graphql.schema.json

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,11 @@
13841384
"name": "cacheControl",
13851385
"description": null,
13861386
"isRepeatable": false,
1387-
"locations": ["FIELD_DEFINITION", "OBJECT", "INTERFACE"],
1387+
"locations": [
1388+
"FIELD_DEFINITION",
1389+
"OBJECT",
1390+
"INTERFACE"
1391+
],
13881392
"args": [
13891393
{
13901394
"name": "maxAge",
@@ -1416,7 +1420,11 @@
14161420
"name": "include",
14171421
"description": "Directs the executor to include this field or fragment only when the `if` argument is true.",
14181422
"isRepeatable": false,
1419-
"locations": ["FIELD", "FRAGMENT_SPREAD", "INLINE_FRAGMENT"],
1423+
"locations": [
1424+
"FIELD",
1425+
"FRAGMENT_SPREAD",
1426+
"INLINE_FRAGMENT"
1427+
],
14201428
"args": [
14211429
{
14221430
"name": "if",
@@ -1440,7 +1448,11 @@
14401448
"name": "skip",
14411449
"description": "Directs the executor to skip this field or fragment when the `if` argument is true.",
14421450
"isRepeatable": false,
1443-
"locations": ["FIELD", "FRAGMENT_SPREAD", "INLINE_FRAGMENT"],
1451+
"locations": [
1452+
"FIELD",
1453+
"FRAGMENT_SPREAD",
1454+
"INLINE_FRAGMENT"
1455+
],
14441456
"args": [
14451457
{
14461458
"name": "if",
@@ -1489,7 +1501,9 @@
14891501
"name": "specifiedBy",
14901502
"description": "Exposes a URL that specifies the behaviour of this scalar.",
14911503
"isRepeatable": false,
1492-
"locations": ["SCALAR"],
1504+
"locations": [
1505+
"SCALAR"
1506+
],
14931507
"args": [
14941508
{
14951509
"name": "url",
@@ -1511,4 +1525,4 @@
15111525
}
15121526
]
15131527
}
1514-
}
1528+
}

src/App.tsx

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,10 @@
11
import React from "react";
22
import "./App.css";
3-
import { gql } from "@apollo/client/core";
4-
import { useUsersQuery } from "./generated/graphql";
3+
import { useUsersListQuery } from "./generated/graphql";
54
import { CreateUserForm } from "./CreateUserForm";
65

7-
const USER_FRAGMENT_GQL = gql`
8-
fragment UserInfo on User {
9-
id
10-
name
11-
username
12-
email
13-
}
14-
`;
15-
16-
const USERS_GQL = gql`
17-
query users {
18-
users {
19-
...UserInfo
20-
}
21-
}
22-
${USER_FRAGMENT_GQL}
23-
`;
24-
25-
const USER_GQL = gql`
26-
query user($id: ID!) {
27-
user(id: $id) {
28-
...UserInfo
29-
}
30-
}
31-
${USER_FRAGMENT_GQL}
32-
`;
33-
34-
const CREATE_USER_GQL = gql`
35-
mutation createUser($createUserInput: CreateUserInput!) {
36-
createUser(createUserInput: $createUserInput) {
37-
...UserInfo
38-
}
39-
}
40-
${USER_FRAGMENT_GQL}
41-
`;
42-
43-
const REMOVE_USER_GQL = gql`
44-
mutation removeUser($id: ID!) {
45-
removeUser(id: $id)
46-
}
47-
`;
48-
49-
const UPDATE_USER_GQL = gql`
50-
mutation updateUser($id: ID!, $updateUserInput: UpdateUserInput!) {
51-
updateUser(id: $id, updateUserInput: $updateUserInput) {
52-
...UserInfo
53-
}
54-
}
55-
${USER_FRAGMENT_GQL}
56-
`;
57-
586
function App() {
59-
const { data, loading, error } = useUsersQuery();
7+
const { data, loading, error } = useUsersListQuery();
608

619
return (
6210
<div className="App">

0 commit comments

Comments
 (0)