Defining our GraphQL types, queries, and mutations
Now that you have created your Apollo Server instance, the next step is to create your GraphQL types. When setting up a GraphQL server like Apollo, creating GraphQL types is crucial. These types ensure that the data returned from your API is reliable and conforms to the expected structure. They act as a helpful reference for available data and its expected format. By using types, your application can precisely request the required data, resulting in faster execution and reduced data consumption. Additionally, types help maintain data consistency, resulting in a robust, comprehensible, and efficient API.
Scalar types
The first thing you need to do is define your scalar types at /backend/src/graphql/types/Scalar.ts
:
import gql from 'graphql-tag'
export default gql`
scalar UUID
scalar Datetime
scalar JSON
Now, let’s create our User
type (backend/src/graphql/types/User.ts
):
import gql from ...