Skip to content

Releases: modevol-com/gqloom

0.7.0

04 Feb 08:33
Compare
Choose a tag to compare

What's Changed

  • feat(resolver): implement ChainFactory for resolver composition in #14
  • feat: Integration with Drizzle ORM in #12
  • refactor(prisma): rename Bobbin to PrismaResolverFactory
  • refactor(mikro-orm): rename MikroOperationBobbin to MikroResolverFactory

Full Changelog: https://github.com/modevol-com/gqloom/compare/@gqloom/core@0.6.0...0.7.0

Resolver Chained Construction

In the old version of GQLoom, we declared operations by passing a resolution option as the second parameter to methods such as query and field. The code looked like this:

import { query, resolver } from "@gqloom/core"
import * as v from "valibot"

export const helloResolver = resolver({
  hello: query(v.string(), {
    input: { name: v.nullish(v.string(), "World") },
    resolve: ({ name }) => `Hello, ${name}!`,
  }),
})

Now we can use the chained calls of methods such as query and field to declare operations, which will make the development experience easier. The code now looks like this:

import { query, resolver } from "@gqloom/core"
import * as v from "valibot"

export const helloResolver = resolver({
  hello: query(v.string())
    .input({ name: v.nullish(v.string(), "World") })
    .resolve(({ name }) => `Hello, ${name}!`),
})

Drizzle Integration

GQLoom now provides integration with Drizzle:

  • Use Drizzle Schema as Silk;
  • Use the resolver factory to quickly create CRUD operations from Drizzle.

Here is an example of using both Drizzle and GQLoom:

// schema.ts
import { drizzleSilk } from "@gqloom/drizzle"
import { relations } from "drizzle-orm"
import * as t from "drizzle-orm/sqlite-core"

export const users = drizzleSilk(
  t.sqliteTable("users", {
    id: t.int().primaryKey({ autoIncrement: true }),
    name: t.text().notNull(),
    age: t.int(),
    email: t.text(),
    password: t.text(),
  })
)

export const usersRelations = relations(users, ({ many }) => ({
  posts: many(posts),
}))

export const posts = drizzleSilk(
  t.sqliteTable("posts", {
    id: t.int().primaryKey({ autoIncrement: true }),
    title: t.text().notNull(),
    content: t.text(),
    authorId: t.int().references(() => users.id, { onDelete: "cascade" }),
  })
)

export const postsRelations = relations(posts, ({ one }) => ({
  author: one(users, {
    fields: [posts.authorId],
    references: [users.id],
  }),
}))
// resolver.ts
import { query, resolver } from "@gqloom/core"
import { drizzleResolverFactory } from "@gqloom/drizzle"
import { eq } from "drizzle-orm"
import { drizzle } from "drizzle-orm/libsql"
import * as v from "valibot"
import * as schema from "./schema.ts"
import { users } from "./schema.ts"

const db = drizzle({
  schema,
  connection: { url: process.env.DB_FILE_NAME! },
})

const usersResolverFactory = drizzleResolverFactory(db, "users")

export const usersResolver = resolver.of(users, {
  user: query
    .output(users.$nullable())
    .input({ id: v.number() })
    .resolve(({ id }) => {
      return db.select().from(users).where(eq(users.id, id)).get()
    }),

  users: usersResolverFactory.selectArrayQuery(),

  posts: usersResolverFactory.relationField("posts"), 
})

Learn more in the Drizzle Integration Documentation!

@gqloom/core@0.6.0

12 Dec 20:11
Compare
Choose a tag to compare

What's Changed

  • feat(core): implement automatic type aliasing by @xcfox in #9
  • refactor(core): rename SchemaWeaver to GraphQLSchemaLoom
  • build(deps): update zod to 3.24.0 by @xcfox in #8

Full Changelog: https://github.com/modevol-com/gqloom/compare/@gqloom/core@0.5.0...@gqloom/core@0.6.0

@gqloom/core@0.5.0

03 Dec 14:27
Compare
Choose a tag to compare

What's Changed

  • Fix: add all objects in resolver.of to context.types
  • Chore: update @standard-schema/spec to 1.0.0-beta.4
  • Refactor: update CallableMiddlewareOptions for middleware

@gqloom/core@0.4.0

19 Nov 16:12
Compare
Choose a tag to compare

What's Changed

  • Refactor: follow standard-schema (#7)