Google Antigravity Directory

The #1 directory for Google Antigravity prompts, rules, workflows & MCP servers. Optimized for Gemini 3 agentic development.

Resources

PromptsMCP ServersAntigravity RulesGEMINI.md GuideBest Practices

Company

Submit PromptAntigravityAI.directory

Popular Prompts

Next.js 14 App RouterReact TypeScriptTypeScript AdvancedFastAPI GuideDocker Best Practices

Legal

Privacy PolicyTerms of ServiceContact Us
Featured on FazierFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowAI ToolzShinyLaunchMillion Dot HomepageSolver ToolsFeatured on FazierFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowAI ToolzShinyLaunchMillion Dot HomepageSolver Tools

© 2026 Antigravity AI Directory. All rights reserved.

The #1 directory for Google Antigravity IDE

This website is not affiliated with, endorsed by, or associated with Google LLC. "Google" and "Gemini" are trademarks of Google LLC.

Antigravity AI Directory
PromptsMCPBest PracticesUse CasesLearn
Home
Prompts
GraphQL Schema SDL Patterns

GraphQL Schema SDL Patterns

Best practices for designing scalable GraphQL schemas with type safety and efficient resolvers for Google Antigravity.

graphqlapischematypescriptapollo
by antigravity-team
⭐0Stars
.antigravity
# GraphQL Schema SDL Patterns for Google Antigravity

GraphQL provides a powerful query language for APIs with strong typing and flexible data fetching. Google Antigravity's Gemini 3 helps you design well-structured schemas that scale with your application's needs.

## Schema-First Design

Start with a well-organized schema using SDL (Schema Definition Language):

```graphql
# schema.graphql

scalar DateTime
scalar UUID
scalar EmailAddress

enum UserRole {
  USER
  ADMIN
  MODERATOR
}

enum PostStatus {
  DRAFT
  PUBLISHED
  ARCHIVED
}

input CreateUserInput {
  email: EmailAddress!
  name: String!
  role: UserRole
}

input UpdateUserInput {
  name: String
  bio: String
  avatarUrl: String
}

input CreatePostInput {
  title: String!
  content: String!
  categoryIds: [UUID!]
  tags: [String!]
}

interface Node {
  id: UUID!
}

interface Timestamped {
  createdAt: DateTime!
  updatedAt: DateTime!
}

type User implements Node & Timestamped {
  id: UUID!
  email: EmailAddress!
  name: String!
  role: UserRole!
  bio: String
  avatarUrl: String
  posts(first: Int, after: String): PostConnection!
  createdAt: DateTime!
  updatedAt: DateTime!
}

type Post implements Node & Timestamped {
  id: UUID!
  title: String!
  content: String!
  status: PostStatus!
  author: User!
  categories: [Category!]!
  tags: [String!]!
  viewCount: Int!
  createdAt: DateTime!
  updatedAt: DateTime!
}

type Category implements Node {
  id: UUID!
  name: String!
  slug: String!
  posts(first: Int, after: String): PostConnection!
}

type PageInfo {
  hasNextPage: Boolean!
  hasPreviousPage: Boolean!
  startCursor: String
  endCursor: String
}

type PostEdge {
  cursor: String!
  node: Post!
}

type PostConnection {
  edges: [PostEdge!]!
  pageInfo: PageInfo!
  totalCount: Int!
}

type Query {
  me: User
  user(id: UUID!): User
  users(first: Int, after: String, role: UserRole): UserConnection!
  post(id: UUID!): Post
  posts(
    first: Int
    after: String
    status: PostStatus
    authorId: UUID
    categoryId: UUID
  ): PostConnection!
  categories: [Category!]!
  search(query: String!, first: Int): SearchResultConnection!
}

type Mutation {
  createUser(input: CreateUserInput!): User!
  updateUser(id: UUID!, input: UpdateUserInput!): User!
  deleteUser(id: UUID!): Boolean!
  
  createPost(input: CreatePostInput!): Post!
  updatePost(id: UUID!, input: UpdatePostInput!): Post!
  publishPost(id: UUID!): Post!
  deletePost(id: UUID!): Boolean!
}

type Subscription {
  postPublished: Post!
  newComment(postId: UUID!): Comment!
}
```

## TypeScript Code Generation

Use GraphQL Code Generator for type safety:

```typescript
// codegen.ts
import { CodegenConfig } from "@graphql-codegen/cli";

const config: CodegenConfig = {
  schema: "./schema.graphql",
  documents: ["src/**/*.graphql", "src/**/*.tsx"],
  generates: {
    "./src/generated/graphql.ts": {
      plugins: [
        "typescript",
        "typescript-operations",
        "typescript-react-apollo",
      ],
      config: {
        strictScalars: true,
        scalars: {
          DateTime: "string",
          UUID: "string",
          EmailAddress: "string",
        },
        withHooks: true,
        withComponent: false,
        withHOC: false,
      },
    },
  },
};

export default config;
```

## Resolver Implementation

Implement type-safe resolvers with context:

```typescript
// resolvers/index.ts
import { Resolvers } from "@/generated/graphql";
import { Context } from "@/lib/context";
import { GraphQLError } from "graphql";

export const resolvers: Resolvers<Context> = {
  Query: {
    me: async (_, __, { user }) => {
      if (!user) return null;
      return user;
    },

    user: async (_, { id }, { prisma }) => {
      return prisma.user.findUnique({
        where: { id },
      });
    },

    posts: async (_, { first = 10, after, status, authorId }, { prisma }) => {
      const cursor = after ? { id: after } : undefined;
      const where = {
        ...(status && { status }),
        ...(authorId && { authorId }),
      };

      const posts = await prisma.post.findMany({
        take: first + 1,
        skip: after ? 1 : 0,
        cursor,
        where,
        orderBy: { createdAt: "desc" },
      });

      const hasNextPage = posts.length > first;
      const edges = posts.slice(0, first).map((post) => ({
        cursor: post.id,
        node: post,
      }));

      return {
        edges,
        pageInfo: {
          hasNextPage,
          hasPreviousPage: !!after,
          startCursor: edges[0]?.cursor,
          endCursor: edges[edges.length - 1]?.cursor,
        },
        totalCount: await prisma.post.count({ where }),
      };
    },
  },

  Mutation: {
    createPost: async (_, { input }, { user, prisma }) => {
      if (!user) {
        throw new GraphQLError("Not authenticated", {
          extensions: { code: "UNAUTHENTICATED" },
        });
      }

      return prisma.post.create({
        data: {
          title: input.title,
          content: input.content,
          authorId: user.id,
          status: "DRAFT",
          categories: {
            connect: input.categoryIds?.map((id) => ({ id })) || [],
          },
          tags: input.tags || [],
        },
      });
    },

    publishPost: async (_, { id }, { user, prisma }) => {
      const post = await prisma.post.findUnique({ where: { id } });
      
      if (!post) {
        throw new GraphQLError("Post not found", {
          extensions: { code: "NOT_FOUND" },
        });
      }

      if (post.authorId !== user?.id) {
        throw new GraphQLError("Not authorized", {
          extensions: { code: "FORBIDDEN" },
        });
      }

      return prisma.post.update({
        where: { id },
        data: { status: "PUBLISHED" },
      });
    },
  },

  User: {
    posts: async (parent, { first = 10, after }, { prisma }) => {
      const posts = await prisma.post.findMany({
        where: { authorId: parent.id },
        take: first + 1,
        skip: after ? 1 : 0,
        cursor: after ? { id: after } : undefined,
        orderBy: { createdAt: "desc" },
      });

      const hasNextPage = posts.length > first;
      const edges = posts.slice(0, first).map((post) => ({
        cursor: post.id,
        node: post,
      }));

      return {
        edges,
        pageInfo: {
          hasNextPage,
          hasPreviousPage: !!after,
          startCursor: edges[0]?.cursor,
          endCursor: edges[edges.length - 1]?.cursor,
        },
        totalCount: await prisma.post.count({ where: { authorId: parent.id } }),
      };
    },
  },

  Post: {
    author: async (parent, _, { dataloaders }) => {
      return dataloaders.userLoader.load(parent.authorId);
    },

    categories: async (parent, _, { prisma }) => {
      return prisma.category.findMany({
        where: {
          posts: { some: { id: parent.id } },
        },
      });
    },
  },
};
```

## DataLoader for N+1 Prevention

Implement efficient data loading:

```typescript
// lib/dataloaders.ts
import DataLoader from "dataloader";
import { PrismaClient, User, Category } from "@prisma/client";

export function createDataLoaders(prisma: PrismaClient) {
  return {
    userLoader: new DataLoader<string, User>(async (ids) => {
      const users = await prisma.user.findMany({
        where: { id: { in: [...ids] } },
      });
      const userMap = new Map(users.map((u) => [u.id, u]));
      return ids.map((id) => userMap.get(id)!);
    }),

    categoryLoader: new DataLoader<string, Category>(async (ids) => {
      const categories = await prisma.category.findMany({
        where: { id: { in: [...ids] } },
      });
      const categoryMap = new Map(categories.map((c) => [c.id, c]));
      return ids.map((id) => categoryMap.get(id)!);
    }),
  };
}
```

## Best Practices

1. **Use interfaces for shared fields** - Promote schema consistency
2. **Implement cursor-based pagination** - Scale better than offset pagination
3. **Use DataLoader** - Prevent N+1 query problems
4. **Define clear input types** - Separate mutation inputs from query types
5. **Add proper error codes** - Help clients handle errors appropriately

GraphQL with Google Antigravity enables rapid API development with intelligent schema suggestions and type-safe resolver generation.

When to Use This Prompt

This graphql prompt is ideal for developers working on:

  • graphql applications requiring modern best practices and optimal performance
  • Projects that need production-ready graphql code with proper error handling
  • Teams looking to standardize their graphql development workflow
  • Developers wanting to learn industry-standard graphql patterns and techniques

By using this prompt, you can save hours of manual coding and ensure best practices are followed from the start. It's particularly valuable for teams looking to maintain consistency across their graphql implementations.

How to Use

  1. Copy the prompt - Click the copy button above to copy the entire prompt to your clipboard
  2. Paste into your AI assistant - Use with Claude, ChatGPT, Cursor, or any AI coding tool
  3. Customize as needed - Adjust the prompt based on your specific requirements
  4. Review the output - Always review generated code for security and correctness
💡 Pro Tip: For best results, provide context about your project structure and any specific constraints or preferences you have.

Best Practices

  • ✓ Always review generated code for security vulnerabilities before deploying
  • ✓ Test the graphql code in a development environment first
  • ✓ Customize the prompt output to match your project's coding standards
  • ✓ Keep your AI assistant's context window in mind for complex requirements
  • ✓ Version control your prompts alongside your code for reproducibility

Frequently Asked Questions

Can I use this graphql prompt commercially?

Yes! All prompts on Antigravity AI Directory are free to use for both personal and commercial projects. No attribution required, though it's always appreciated.

Which AI assistants work best with this prompt?

This prompt works excellently with Claude, ChatGPT, Cursor, GitHub Copilot, and other modern AI coding assistants. For best results, use models with large context windows.

How do I customize this prompt for my specific needs?

You can modify the prompt by adding specific requirements, constraints, or preferences. For graphql projects, consider mentioning your framework version, coding style, and any specific libraries you're using.

Related Prompts

💬 Comments

Loading comments...