Implementation (NodeJS + React)

Server-Side (NodeJS Express)

Pre-Action

npm install apollo-server-express

Structure

Data

  • Define the data source

const studentList =  [
    { sid: 1, name: "Peter", age: 18, courseId: [1,3]},
    { sid: 2, name: "Mary", age: 23, courseId: [1,2]}
];

const courseList = [
    { cid: 1, name: "Chinese", studentId:[1,2] },
    { cid: 2, name: "English", studentId: [2] },
    { cid: 3, name: "Math", studentId:[1]}
]

export {studentList, courseList};

Schema

  • Define what type of input can be entered, the format of query, type, ......

  • Separate by domain (e.g: Student and Course)

  • Then group them together

Resolver

  • Define the implementation of the query, mutation, ......

  • Separate by domain (e.g: Student and Course)

  • Then put them together

Output

  • Group data, schema and resolver together

Result

Client-Side (React)

Pre-Action

Configuration

Hook

  • useQuery (To get the ideal format of data from API End Point)

  • useMutation (Update or Insert the new data)

Result

REST API + GraphQL

  • we can let rest api as a datasource, reformat the format of data by using graphql

Pre-Action

Data Source

Schema

Resolver

Integration

Last updated

Was this helpful?