Skip to content

Commit 506edd5

Browse files
author
Sashko Stubailo
committed
Sketch of new schema
1 parent e67270b commit 506edd5

File tree

2 files changed

+116
-19
lines changed

2 files changed

+116
-19
lines changed

site/docs/Learn-Schema.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ The most basic components of a GraphQL schema are object types, which just repre
4141
```graphql
4242
type Character {
4343
name: String!
44-
appearsIn: [Episode]
44+
appearsIn: [Episode]!
4545
}
4646
```
4747

@@ -55,6 +55,11 @@ The language is pretty readable, but let's go over it so that we can have a shar
5555

5656
Now you know what a GraphQL object type looks like, and how to read the basics of the GraphQL type language.
5757

58+
### Arguments
59+
60+
TODO
61+
- Include the idea of default arguments
62+
5863
### The Query and Mutation types
5964

6065
Most types in your schema will just be normal object types, but there are two types that are special within a schema:
@@ -85,7 +90,7 @@ That means that the GraphQL service needs to have a `Query` type with `hero` and
8590
```graphql
8691
type Query {
8792
hero(episode: Episode): Character
88-
droid(id: ID!): Droid
93+
droid(id: String!): Droid
8994
}
9095
```
9196

@@ -155,7 +160,7 @@ Object types, scalars, and enums are the only kinds of types you can define in G
155160
```graphql
156161
type Character {
157162
name: String!
158-
appearsIn: [Episode]
163+
appearsIn: [Episode]!
159164
}
160165
```
161166

@@ -213,9 +218,9 @@ For example, you could have an interface `Character` that represents any charact
213218
```graphql
214219
interface Character {
215220
id: String!
216-
name: String
221+
name: String!
217222
friends: [Character]
218-
appearsIn: [Episode]
223+
appearsIn: [Episode]!
219224
}
220225
```
221226

@@ -226,17 +231,17 @@ For example, here are some types that might implement `Character`:
226231
```graphql
227232
type Human implements Character {
228233
id: String!
229-
name: String
234+
name: String!
230235
friends: [Character]
231-
appearsIn: [Episode]
236+
appearsIn: [Episode]!
232237
homePlanet: String
233238
}
234239

235240
type Droid implements Character {
236241
id: String!
237-
name: String
242+
name: String!
238243
friends: [Character]
239-
appearsIn: [Episode]
244+
appearsIn: [Episode]!
240245
primaryFunction: String
241246
}
242247
```

site/docs/_swapiSchema.js

Lines changed: 102 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,109 @@ import {
1616
GraphQLString
1717
} from 'graphql';
1818

19+
const schemaString = `
20+
schema {
21+
query: Query
22+
mutation: Mutation
23+
}
24+
25+
type Query {
26+
hero(episode: Episode): Character
27+
search(query: String): [SearchResult]
28+
}
29+
30+
# The episodes in the Star Wars trilogy
31+
enum Episode {
32+
# Star Wars Episode IV: A New Hope, released in 1977.
33+
NEWHOPE
34+
35+
# Star Wars Episode V: The Empire Strikes Back, released in 1980.
36+
EMPIRE
37+
38+
# Star Wars Episode VI: Return of the Jedi, released in 1983.
39+
JEDI
40+
}
41+
42+
# A character from the Star Wars universe
43+
interface Character {
44+
# The ID of the character
45+
id: ID!
46+
47+
# The name of the character
48+
name: String!
49+
50+
# The friends of the character, or an empty list if they have none
51+
friends: [Character]
52+
53+
# The movies this character appears in
54+
appearsIn: [Episode]!
55+
}
56+
57+
# A humanoid creature from the Star Wars universe
58+
type Human implements Character {
59+
# The ID of the human
60+
id: ID!
61+
62+
# What this human calls themselves
63+
name: String!
64+
65+
# This human's friends, or an empty list if they have none
66+
friends: [Character]
67+
68+
# The movies this human appears in
69+
appearsIn: [Episode]!
70+
71+
# A list of starships this person has piloted, or an empty list if none
72+
starships: [Starship]
73+
}
74+
75+
# An autonomous mechanical character in the Star Wars universe
76+
type Droid implements Character {
77+
# The ID of the droid
78+
id: ID!
79+
80+
# What others call this droid
81+
name: String!
82+
83+
# This droid's friends, or an empty list if they have none
84+
friends: [Character]
85+
86+
# The movies this droid appears in
87+
appearsIn: [Episode]!
88+
89+
# This droid's primary function
90+
primaryFunction: String
91+
}
92+
93+
# Units of length
94+
enum LengthUnit {
95+
# The standard unit around the world
96+
METER
97+
98+
# Primarily used in the United States
99+
FOOT
100+
}
101+
102+
type Starship {
103+
# The ID of the starship
104+
id: ID!
105+
106+
# The name of the starship
107+
name: String!
108+
109+
# The length of the starship, in meters
110+
length(unit: LengthUnit = METER): Float!
111+
}
112+
113+
union SearchResult = Character | Starship
114+
`;
115+
116+
117+
118+
119+
120+
19121

20-
/**
21-
* This is designed to be an end-to-end test, demonstrating
22-
* the full GraphQL stack.
23-
*
24-
* We will create a GraphQL schema that describes the major
25-
* characters in the original Star Wars trilogy.
26-
*
27-
* NOTE: This may contain spoilers for the original Star
28-
* Wars trilogy.
29-
*/
30122

31123
/**
32124
* This defines a basic set of data for our Star Wars Schema.

0 commit comments

Comments
 (0)