Welcome to the world of direct GraphQL API calls! This guide will show you how to make direct calls to a GraphQL API using the graphql-agent-tool
. It's like having a direct line to your favorite GraphQL endpoint! 🎯
The GraphQL Agent Tool provides a simple and type-safe way to make direct GraphQL API calls from your application. Whether you're building a web app, mobile app, or backend service, this tool makes it easy to interact with any GraphQL API. 🌟
Here's how you can use the tool directly in your application:
import { GraphqlAgentTool } from "graphql-agent-tool";
const graphqlCapitalTool = new GraphqlAgentTool({
name: "getCountryCapital",
purpose: "Retrieves the capital city of a country using its ISO country code...",
url: "https://countries.trevorblades.com",
query: `
query GetCountryCapital($countryCode: ID!) {
country(code: $countryCode) {
capital
}
}
`,
}).getTool();
// Direct invocation
const response = await graphqlCapitalTool.invoke({
variables: {
countryCode: "IN", // Try "US", "GB", "FR" for other countries!
},
});
getCountryCapital
) so we know what it doesReady to level up? Check out our other guides on:
Happy coding! 🎉