open-source-labs / obsidian

GraphQL, built for Deno - a native GraphQL caching client and server module

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when trying to run the 'Getting Started' code

agustinmulet opened this issue · comments

Hi everyone, thanks for the hard work! I'm having some trouble trying to run a simple API with the code provided on the Getting Started section, I'll leave the details and my findings and please tell me if there's something I'm doing wrong.
First some specs:

OS: W10 with Ubuntu 20.04 (WSL)
Deno: v1.9.0
Obsidian: v3.0.0
Redis-server: v5.0.7

This is the code I have from the docs:

// server.tsx
import { Application, Router } from 'https://deno.land/x/oak@v6.0.1/mod.ts';
import { ObsidianRouter, gql } from 'https://deno.land/x/obsidian/mod.ts';

const PORT = 8000;

const app = new Application();

const types = (gql as any)`
  type Movie {
    id: ID
    title: String
    releaseYear: Int
  }

  type Query {
    getMovie: Movie
  }
`;

const resolvers = {
  Query: {
    getMovie: () => {
      return {
        id: "1",
        title: "Up",
        releaseYear: 2009
      };
    },
  },
};

interface ObsRouter extends Router {
  obsidianSchema?: any;
}

const GraphQLRouter = await ObsidianRouter<ObsRouter>({
  Router,
  typeDefs: types,
  resolvers: resolvers,
  useCache: false,
});

app.use(GraphQLRouter.routes(), GraphQLRouter.allowedMethods());

app.addEventListener('listen', () => {
  console.log(`Listening at http://localhost:${PORT}`);
});

await app.listen({ port: PORT });

And when I try to run with the flags that the CLI needed deno run --allow-net --allow-read --allow-env --unstable server.tsx and also creating a .env file with REDIS_HOST=6379 I'm getting this error:

error: Uncaught (in promise) TypeError: Invalid argument (os error 22)
        : await Deno.connect(dialOpts);
          ^
    at unwrapOpResult (deno:core/core.js:100:13)
    at async Object.connect (deno:runtime/js/30_net.js:199:13)
    at async RedisConnection.connectThunkified (https://deno.land/x/redis@v0.21.0/connection.ts:74:11)
    at async RedisConnection.connect (https://deno.land/x/redis@v0.21.0/connection.ts:123:5)
    at async connect (https://deno.land/x/redis@v0.21.0/redis.ts:2265:3)
    at async https://deno.land/x/obsidian@3.0.0/src/CacheClassServer.js:10:11

Doing some research seems like the os error 22 has something to do with sockets? And also I found that that line (: await Deno.connect(dialOpts) is here on the redis repo https://deno.land/x/redis@v0.22.0/connection.ts#L74 and I don't know why it could be failing since I've tried to run this simple file to check if the redis server connection is alive and I'm seeing PONG as a response:

import { connect } from "https://deno.land/x/redis/mod.ts";
const redis = await connect({
  hostname: "127.0.0.1",
  port: 6379
});
console.log(await redis.ping())

I guess I'm missing something since I don't know much about redis, hope someone can point me in the right direction

Hey @agustinmulet, thanks for bringing this issue forward. It appears that you're using the wrong value for REDIS_HOST. REDIS_HOST should be, as you correctly wrote in your final snippet, the hostname, not the port. Earlier you mentioned using 6379 as the value, which is incorrect. Let me know if this helps!

As an aside, I'll be updating the docs in the next couple weeks to bring them in line with 3.0. Please let me know if you find anything unclear or out-of-date. Cheers!

Oh nice! I misinterpreted and used the port. Thanks a lot @TravisFrankMTG !
The server is starting now but graphql playground is not showing up on http://localhost:8000/graphql (even tried with https), I'm getting a 404. I'll test this with a mac I have to see if this has something to do with WSL. Again, thanks!