Basics Flashcards

1
Q

What is a schema definition?

A

A schema is a collection ofobject typesthat containfields. Each field has a type of its own. A field’s type can bescalar(such as anIntor aString), or it can beanother object type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How declare a type?

A

We declare a type using the type keyword, followed by the name of the type (PascalCase is best practice), then opening brackets to hold its contained fields:

type SpaceCat {
# Fields go here
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How define a field?

A

Fields are declared by their name (camelCase), a colon, and then the type of the field (scalar or object). A field can also contain a list, indicated by square brackets:

type SpaceCat {
age: Int
missions: [Mission]
}

Unlike Javascript objects (which look very similar), fields are not separated by commas. In addition, we can indicate whether each field value is nullable or non-nullable. If a field should never be null, we add an exclamation mark after its type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which of the following are valid field types?
Int
String
String!
[Int]

A

All of them

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Define a SpaceCat type with the following fields: name of type String (non null), age of type Int, and missions of type List of Mission

A

type SpaceCat {
name: String!
age: Int
missions: [Mission]
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to add schema descriptions?

A

To do that, the SDL lets you add descriptions to both types and fields by writing strings (in quotation marks) directly above them.

“I’m a regular description”
Triple “double quotes” allow you to add line breaks for clearer formatting of lengthier comments.

”””
I’m a block description
with a line break

”””

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How define an endpoint to get data?

A

Creating a type Query:

type Query {
# Fields go here
}

The fields of this type are entry points into the rest of our schema. These are the top-level fields that our client can query for.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

[Code Challange] Create a full schema with: a type Query containing a field spaceCats to fetch a List of SpaceCat. A type SpaceCat with its subfields: id of type ID!, name of type String!, age of type Int and missions of type List of Mission. Finally define the Mission type with its subfields: id of type ID!, name of type String!, and description of type String!.

A

type Query {
“Get Space Cats”
spaceCats: [SpaceCat]
}

type SpaceCat {
id: ID!
name: String!
age: Int
missions: [Mission]
}

type Mission {
id: ID!
name: String!
description: String!
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which of these are purposes of a GraphQL server?

1 - Receiving incoming GraphQL queries
2 - Validating GraphQL queries against our schema
3 - Creating GraphQL queries
4 - Exposing a separate endpoint for each schema type
5 - Returning populated schema fields as a response

A

(V) 1 - Receiving incoming GraphQL queries
(V) 2 - Validating GraphQL queries against our schema
(F) 3 - Creating GraphQL queries
(F) 4 - Exposing a separate endpoint for each schema type
(V) 5 - Returning populated schema fields as a response

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which of these are purposes of a GraphQL server?

1 - Receiving incoming GraphQL queries
2 - Validating GraphQL queries against our schema
3 - Creating GraphQL queries
4 - Exposing a separate endpoint for each schema type
5 - Returning populated schema fields as a response

A

(V) 1 - Receiving incoming GraphQL queries
(V) 2 - Validating GraphQL queries against our schema
(F) 3 - Creating GraphQL queries
(F) 4 - Exposing a separate endpoint for each schema type
(V) 5 - Returning populated schema fields as a response

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which of these are benefits of using the Apollo Studio Explorer?

A

You can step through your schema to discover available types and fields

You can build and iterate on queries faster

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do we make Apollo Client available to our app’s React components?

A

We wrap our React component tree in the ApolloProvider component

https://www.apollographql.com/tutorials/lift-off-part1/08-apollo-client-setup

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

[Code Challange] Create a ListSpaceCats query with a spaceCats query field and its name, age and missions selection set in that order. For the missions field, select name and description

A

query ListSpaceCats {
spaceCats {
name
age
missions {
name
description
}
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the best practices when creating client queries?

A

Include only the fields that the client requires.
Wrap each query in the gql template literal.
Test out queries in the Apollo Studio Explorer and copy then over
Assign each query string to a constant with an ALL_CAPS name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly