GraphQL 6 (09.01.2023 M) Flashcards
Give an example Mutation type declaration.
Mutation declaration starts from “type” keyword followed by “Mutation” followed by the declaration of fields between {}. See the example image.
Declaration of Mutation type is the same as for ordinary objects. And looks like this.
< fieldName >(< comma separated list of < argument > >): < fieldType >
< argument > = < argumentName >: < argumentType > [ = < default value > ]
What is scalar types in GraphQL?
A GraphQL object type has a name and fields, but at some point, those fields have to resolve to some concrete data. That’s where the scalar types come in: they don’t have any sub-fields and represent the leaves of the query.
List out of the box GraphQL scalar types?
- Int: A signed 32‐bit integer.
- Float: A signed double-precision floating-point value.
- String: A UTF‐8 character sequence.
- Boolean: true or false.
- ID: The ID scalar type represents a unique identifier, often used to refetch an object or as the key for a cache. The ID type is serialized in the same way as a String; however, defining it as an ID signifies that it is not intended to be human‐readable.
Can custom scalar types be defined?
Yes. In most GraphQL service implementations, there is also a way to specify custom scalar types.
Describe scalar type definition in schema. What is required from server to be done in order to support custom scalar types?
- Scalar type definition starts from “scalar” keyword followed by scalar type name.
scalar < scalarTypeName >
- It’s up to the implementation to define how that type should be serialized, deserialized, and validated. For example, you could specify that the Date type should always be serialized into an integer timestamp, and your client should know to expect that format for any date fields.
What is Enumeration Type? Give an example.
Enumeration types are a special kind of scalar that is restricted to a particular set of allowed values.
When you provide enum value as an argument it looks like string. Value is key sensitive and by convention they are in all upper-case.
For example:
{
“ep”: “JEDI”
}
What kind of types you can define in GraphQL?
Object types, scalars, and enums are the only concrete kinds of types you can define.
But you can also create abstract types which are Interfaces and Unions.