Skip to content

Leverage AI to generate GraphQL queries from plain text.

Notifications You must be signed in to change notification settings

rocket-connect/gqlpt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

2ebc526 · Feb 1, 2025
Oct 9, 2024
Feb 1, 2025
Aug 19, 2024
Dec 7, 2024
Dec 7, 2024
Oct 9, 2024
Dec 7, 2024
Sep 30, 2023
Oct 10, 2024
Dec 7, 2024
Dec 7, 2024
Sep 25, 2023
Aug 19, 2024

Repository files navigation

GQLPT

GQLPT

Leverage AI to generate GraphQL queries from plain text.

gqlpt.dev/docs

npm version License: MIT

Image showing the online playground for gqlpt.dev. GQLPT is a npm package that allows you to generate GraphQL queries from plain text using AI.

Installation

https://www.npmjs.com/package/gqlpt

npm install gqlpt @gqlpt/adapter-openai

Usage

import { AdapterOpenAI } from "@gqlpt/adapter-openai";

import { GQLPTClient } from "gqlpt";

const typeDefs = /* GraphQL */ `
  type User {
    id: ID!
    name: String!
  }

  type Query {
    user(id: ID!): User
  }
`;

const client = new GQLPTClient({
  typeDefs,
  adapter: new AdapterOpenAI({
    apiKey: process.env.OPENAI_API_KEY,
  }),
});

async function main() {
  await client.connect();

  const query = "Find users by id 1";

  const response = await client.generateQueryAndVariables(query);

  console.log(response);
  /*
    {
        query: 'query ($id: ID!) {\n  user(id: $id) {\n    id\n    name\n  }\n}',
        variables: { id: '1' }
    }
  */
}

main();

License

MIT - Rocket Connect - https://github.com/rocket-connect