GraphQL schema design, resolvers, and client integration. Use for building GraphQL APIs and front-end queries.
type User {
id: ID!
name: String!
email: String!
posts: [Post!]!
createdAt: DateTime!
}
type Post {
id: ID!
title: String!
content: String!
author: User!
published: Boolean!
}
input CreatePostInput {
title: String!
content: String!
}
type Query {
users: [User!]!
user(id: ID!): User
posts(published: Boolean): [Post!]!
}
type Mutation {
createUser(name: String!, email: String!): User!
createPost(input: CreatePostInput!): Post!
deletePost(id: ID!): Boolean!
}
type Subscription {
postCreated: Post!
}
import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone';
const typeDefs = `#graphql
type Query {
hello: String
}
`;
const resolvers = {
Query: {
hello: () => 'Hello, world!'
}
};
const server = new ApolloServer({ typeDefs, resolvers });
const { url } = await startStandaloneServer(server, { listen: { port: 4000 } });
const resolvers = {
Query: {
users: async (_, __, { dataSources }) => {
return dataSources.userAPI.getUsers();
},
user: async (_, { id }, { dataSources }) => {
return dataSources.userAPI.getUser(id);
}
},
User: {
posts: async (parent, _, { dataSources }) => {
return dataSources.postAPI.getPostsByUser(parent.id);
}
},
Mutation: {
createUser: async (_, { name, email }, { dataSources }) => {
return dataSources.userAPI.createUser({ name, email });
}
}
};
import { gql, useQuery, useMutation } from '@apollo/client';
const GET_USERS = gql`
query GetUsers {
users {
id
name
email
}
}
`;
function Users() {
const { loading, error, data } = useQuery(GET_USERS);
if (loading) return <p>Loading...</p>;
if (error) return <p>Error: {error.message}</p>;
return data.users.map(user => <div key={user.id}>{user.name}</div>);
}
| Practice | Description | |----------|-------------| | Pagination | Use cursor-based pagination | | N+1 Problem | Use DataLoader for batching | | Error Handling | Return errors in extensions | | Versioning | Avoid, use evolution | | Caching | Use Apollo Client cache |
npx skills add lovedragonball/graphql-development下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer