Example 1: Student Object in GraphQL Schema
Below is the example of Student Object which consists the field names of name and roll_number. String data type is the data type of name and roll_number. If we execute this Graphql schema, then the Graphql will only fetch name and roll_number from service for Student Object.
type Student {
name : String
roll_number : String
}
Object Types and Fields in GraphQL Schema
GraphQL is a query language designed to provide a more efficient and flexible alternative to traditional REST APIs. One of its key features is the ability to define Object Types and Fields, which allow developers to structure the data they want to fetch from a server.
Understanding how to create Object Types and Fields is fundamental to building GraphQL schemas and querying data effectively. In this article, We will understand what is object types, fields, and how to create them in GraphQL schema with the help of examples and so on.