DenoDDeno
Powered by
moochM
Denoβ€’16mo ago
mooch

Unable to use @apollo/client

// query github api using graphql
import { ApolloClient, HttpLink, InMemoryCache } from "@apollo/client";
import { RepositoryDocument } from "@hk/github-graphql";

// print something from the github graphql api
export async function demo() {
  const client = new ApolloClient({
    cache: new InMemoryCache(),
    link: new HttpLink({
      uri: "https://api.github.com/graphql",
      headers: {
        authorization: `Bearer ${Deno.env.get("GITHUB_TOKEN")}`,
        "User-Agent": "github-graphql package",
      },
    }),
  });

  const result = await client.query({
    query: RepositoryDocument,
    variables: {
      owner: "tauri-apps",
      name: "tauri",
    },
  });
  console.log(`stargazer count: ${result.data.repository?.stargazerCount}`);
}

await demo();
// query github api using graphql
import { ApolloClient, HttpLink, InMemoryCache } from "@apollo/client";
import { RepositoryDocument } from "@hk/github-graphql";

// print something from the github graphql api
export async function demo() {
  const client = new ApolloClient({
    cache: new InMemoryCache(),
    link: new HttpLink({
      uri: "https://api.github.com/graphql",
      headers: {
        authorization: `Bearer ${Deno.env.get("GITHUB_TOKEN")}`,
        "User-Agent": "github-graphql package",
      },
    }),
  });

  const result = await client.query({
    query: RepositoryDocument,
    variables: {
      owner: "tauri-apps",
      name: "tauri",
    },
  });
  console.log(`stargazer count: ${result.data.repository?.stargazerCount}`);
}

await demo();

I installed these dependencies using
deno add jsr:@hk/github-graphql
deno add jsr:@hk/github-graphql
and
deno add npm:@apollo/client
deno add npm:@apollo/client
. I ran the test program using
deno run -A gql.ts
deno run -A gql.ts


This small program fails with
error: Uncaught SyntaxError: The requested module 'graphql-tag' does not provide an 
export named 'gql'
    at <anonymous> (file:///Users/mooch/p/cts/forgekit/node_modules/.deno/@apollo+cl
ient@3.12.3/node_modules/@apollo/client/core/index.js:34:10)
error: Uncaught SyntaxError: The requested module 'graphql-tag' does not provide an 
export named 'gql'
    at <anonymous> (file:///Users/mooch/p/cts/forgekit/node_modules/.deno/@apollo+cl
ient@3.12.3/node_modules/@apollo/client/core/index.js:34:10)


How do I go about debugging this?
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,934Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

How to use declarations from `vite/client`?
foxpro 🐍Ffoxpro 🐍 / help
3y ago
Unable to use Deno.createHttpClient without deprecated flag --unstable
moneroMmonero / help
3y ago
Deno LSP randomly breaks until a restart (unable to send result to client)
BlockzillaBBlockzilla / help
3y ago
Try to use node-opcua-client (npm) with Deno but struggle
Kiano JajinoKKiano Jajino / help
17mo ago