Back to articles
GraphQL (Apollo) Has a Free API — Here's How to Build Type-Safe APIs

GraphQL (Apollo) Has a Free API — Here's How to Build Type-Safe APIs

via Dev.to JavaScriptAlex Spinov

Apollo GraphQL provides a complete ecosystem for building GraphQL APIs and consuming them in frontend apps — all open-source and free. Apollo Server Setup npm install @apollo/server graphql import { ApolloServer } from " @apollo/server " ; import { startStandaloneServer } from " @apollo/server/standalone " ; const typeDefs = `#graphql type Post { id: ID! title: String! content: String! author: User! tags: [String!]! createdAt: String! } type User { id: ID! name: String! email: String! posts: [Post!]! } type Query { posts(limit: Int, offset: Int): [Post!]! post(id: ID!): Post user(id: ID!): User } type Mutation { createPost(title: String!, content: String!, tags: [String!]): Post! updatePost(id: ID!, title: String, content: String): Post! deletePost(id: ID!): Boolean! } ` ; const resolvers = { Query : { posts : ( _ , { limit = 10 , offset = 0 }) => db . posts . slice ( offset , offset + limit ), post : ( _ , { id }) => db . posts . find ( p => p . id === id ), user : ( _ , { id }) => db

Continue reading on Dev.to JavaScript

Opens in a new tab

Read Full Article
2 views

Related Articles