Dodobibi / postgraphile-nuxt

Module for integrate postgraphile into nuxt. (NOT READY)
1 stars 0 forks source link

Error/Question -- "isTrusted": true #2

Closed stlbucket closed 1 year ago

stlbucket commented 1 year ago

Is there something I am missing?

following these instructions: https://postgraphile.org/postgraphile/next/subscriptions/

In Ruru, I am seeing this error when I try to execute the subscription:

image

from my graphile.config.ts:

image

my plugin is slightly modified:

import { makeExtendSchemaPlugin, gql } from "postgraphile/utils";
import { context, lambda, listen } from "postgraphile/grafast";
import { jsonParse } from "postgraphile/@dataplan/json";
import { EXPORTABLE } from "graphile-export";

const TopicMessageSubscriptionPlugin = makeExtendSchemaPlugin(() => {
  return {
    typeDefs: /* GraphQL */ gql`
      extend type Subscription {
        topicMessage(topicId: UUID!): TopicMessageSubscriptionPayload
      }

      type TopicMessageSubscriptionPayload {
        event: String
        sub: Int
        id: Int
      }
    `,
    plans: {
      Subscription: {
        topicMessage: {
          subscribePlan: EXPORTABLE(
            (lambda, context, listen, jsonParse) => (_$root, args) => {
              const $pgSubscriber = context().get("pgSubscriber");
              const $topicId = args.get("topicId");
              const $topic = lambda($topicId, (id) => `topic:${id}:message`);
              return listen($pgSubscriber, $topic, jsonParse);
            },
            [lambda, context, listen, jsonParse]
          ),
          plan($event) {
            return $event;
          },
        },
      },
      TopicMessageSubscriptionPayload: {
        event($event) {
          return $event.get("event");
        },
        sub($event) {
          return $event.get("sub");
        },
        id($event) {
          return $event.get("id");
        },
      },
    },
  };
});

export default TopicMessageSubscriptionPlugin;
stlbucket commented 1 year ago
image

if i go with the exact grafserv settings in this repository, then my application still works in general, but i cannot get to the /graphiql route

i see the route in the example AND the serv.ts file:

my /server/api/graphql.ts:

import { postgraphile } from "postgraphile"
import { grafserv } from "grafserv/h3/v1";
import preset from "./graphile.config.js";  

const pgl = postgraphile(preset);
const serv = pgl.createServ(grafserv);

export default defineEventHandler(async (event) => {
  return serv.handleEvent(event)  
})

export { serv }

and then in /server/routes/graphiql.ts:

image image
Dodobibi commented 1 year ago

This implementation is waiting pr. You must import grafserv from this local file, not from grafserv since it's not again merged.

import { grafserv } from "./h3/v1";

This must resolve your ws issue too.