This repository demonstrates the usage of GQLPT (GraphQL Plain Text) to query a GraphQL API using natural language. It uses the GitHub GraphQL API as an example.
You can swap between local and remote examples in the retrospective dir in src.
-
Clone this repository:
git clone https://github.com/danstarns/talk-to-graphql cd talk-to-graphql -
Install dependencies:
npm install -
Create a
.envfile in the root directory with the following content:// For using the remote example GQLPT_URL="https://api.github.com/graphql" GQLPT_HEADERS='{"Authorization": "Bearer YOUR_GITHUB_PERSONAL_ACCESS_TOKEN"}' // Required for both local and remote examples OPENAI_API_KEY="YOUR_OPENAI_API_KEY" GQLPT_ADAPTER="openai" // Required for using RAG Vector example NEO4J_URI="bolt://localhost:7687" NEO4J_USER="neo4j" NEO4J_PASSWORD="password"Replace
YOUR_GITHUB_PERSONAL_ACCESS_TOKENwith your actual GitHub Personal Access Token andYOUR_OPENAI_API_KEYwith your OpenAI API key.
-
Generate types:
npm run generate:remote // or :localThis command will generate TypeScript types based on the GraphQL schema.
-
Run the application:
npm run start:remote // or :localThis will execute the remote script, which demonstrates querying the GitHub GraphQL API using plain text.
The main script (remote.ts) does the following:
- Sets up a GQLPT client using the GitHub GraphQL API URL and your OpenAI API key.
- Defines two functions:
getLatestGraphQLIssue(): Retrieves the latest issue from the graphql/graphql-js repository.getGraphQLStarCount(): Fetches the star count of the graphql/graphql-js repository.
- In the
main()function, it calls both of these functions and logs the results.
Feel free to modify the plain text queries in the getLatestGraphQLIssue() and getGraphQLStarCount() functions to experiment with different queries to the GitHub GraphQL API.
If you encounter any issues:
- Ensure all environment variables in the
.envfile are set correctly. - Check that your GitHub Personal Access Token has the necessary permissions.
- Verify that your OpenAI API key is valid and has sufficient credits.
For any other problems, please open an issue in this repository.