Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: CodSpeed

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

permissions:
contents: read
id-token: write

jobs:
benchmarks:
name: Run benchmarks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5

- run: corepack enable
- uses: actions/setup-node@v6
with:
node-version: lts/*
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Run benchmarks
uses: CodSpeedHQ/action@v4
with:
mode: simulation
run: pnpm vitest bench --run
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[![Beta Status][beta-src]][beta-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![Coverage][coverage-src]][coverage-href]
[![CodSpeed][codspeed-src]][codspeed-href]
[![License][license-src]][license-href]
[![Documentation][docs-src]][docs-href]

Expand Down Expand Up @@ -84,3 +85,5 @@ See the [documentation](https://nitro-graphql.pages.dev) for Nuxt and Vite setup
[beta-href]: https://github.com/productdevbook/nitro-graphql/releases
[coverage-src]: https://img.shields.io/badge/coverage-74%25-green?style=flat&colorA=080f12
[coverage-href]: https://github.com/productdevbook/nitro-graphql/actions/workflows/ci.yml
[codspeed-src]: https://img.shields.io/badge/CodSpeed-performance-7c3aed?style=flat&colorA=080f12
[codspeed-href]: https://codspeed.io/productdevbook/nitro-graphql?utm_source=badge
70 changes: 70 additions & 0 deletions benchmarks/directive-parser.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { bench, describe } from 'vitest'
import { DirectiveParser, generateDirectiveSchema } from '../src/core/utils/directive-parser'

const sampleDirectiveFile = `
import { defineDirective } from 'nitro-graphql/define'

export default defineDirective({
name: 'auth',
locations: ['FIELD_DEFINITION', 'OBJECT'],
args: {
requires: {
type: 'String',
defaultValue: 'USER'
}
},
description: 'Checks if user has required permission'
})
`

const complexDirectiveFile = `
import { defineDirective } from 'nitro-graphql/define'

export const cacheDirective = defineDirective({
name: 'cache',
locations: ['FIELD_DEFINITION'],
args: {
ttl: { type: 'Int', defaultValue: 300 },
scope: { type: 'String', defaultValue: 'PUBLIC' }
},
description: 'Cache field results',
isRepeatable: false
})

export const ratelimitDirective = defineDirective({
name: 'ratelimit',
locations: ['FIELD_DEFINITION', 'OBJECT'],
args: {
limit: { type: 'Int' },
window: { type: 'Int', defaultValue: 60 }
},
description: 'Rate limit requests'
})
`

describe('directive Parser Performance', () => {
const parser = new DirectiveParser()

bench('parse single directive', async () => {
await parser.parseDirectives(sampleDirectiveFile, 'directive.ts')
})

bench('parse multiple directives', async () => {
await parser.parseDirectives(complexDirectiveFile, 'directives.ts')
})

bench('generate directive schema', () => {
const directive = {
name: 'auth',
locations: ['FIELD_DEFINITION', 'OBJECT'],
args: {
requires: {
type: 'String',
defaultValue: 'USER',
},
},
description: 'Checks if user has required permission',
}
generateDirectiveSchema(directive)
})
})
71 changes: 71 additions & 0 deletions benchmarks/schema-builder.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { mergeTypeDefs } from '@graphql-tools/merge'
import { buildSchema, parse } from 'graphql'
import { bench, describe } from 'vitest'

const simpleSchema = `
type Query {
hello: String
}
`

const complexSchema = `
type User {
id: ID!
name: String!
email: String!
posts: [Post!]!
}

type Post {
id: ID!
title: String!
content: String!
author: User!
comments: [Comment!]!
}

type Comment {
id: ID!
text: String!
author: User!
}

type Query {
user(id: ID!): User
users: [User!]!
post(id: ID!): Post
posts: [Post!]!
}

type Mutation {
createUser(name: String!, email: String!): User!
createPost(title: String!, content: String!, authorId: ID!): Post!
createComment(text: String!, postId: ID!, authorId: ID!): Comment!
}
`

describe('graphQL Schema Operations', () => {
bench('parse simple schema', () => {
parse(simpleSchema)
})

bench('parse complex schema', () => {
parse(complexSchema)
})

bench('build simple schema', () => {
buildSchema(simpleSchema)
})

bench('build complex schema', () => {
buildSchema(complexSchema)
})

bench('merge multiple schemas', () => {
mergeTypeDefs([simpleSchema, complexSchema], {
throwOnConflict: false,
commentDescriptions: true,
sort: true,
})
})
})
2 changes: 1 addition & 1 deletion native/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nitro-graphql",
"version": "2.0.0-beta.59",
"version": "2.0.0-beta.60",
"napi": {
"binaryName": "graphql-lint",
"packageName": "nitro-graphql",
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nitro-graphql",
"type": "module",
"version": "2.0.0-beta.59",
"version": "2.0.0-beta.60",
"packageManager": "pnpm@10.27.0",
"description": "GraphQL integration for Nitro",
"license": "MIT",
Expand Down Expand Up @@ -128,6 +128,7 @@
"test:ui": "vitest --ui",
"test:run": "vitest run",
"test:coverage": "vitest run --coverage",
"bench": "vitest bench --run",
"typecheck": "tsc --noEmit"
},
"peerDependencies": {
Expand Down Expand Up @@ -183,6 +184,7 @@
},
"devDependencies": {
"@antfu/eslint-config": "catalog:",
"@codspeed/vitest-plugin": "catalog:",
"@napi-rs/cli": "catalog:",
"@nuxt/kit": "catalog:",
"@nuxt/schema": "catalog:",
Expand Down
Loading