Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostGraphiQL supports 'Subscriptions'? #139

Open
Zireael opened this issue Jun 22, 2019 · 4 comments
Open

PostGraphiQL supports 'Subscriptions'? #139

Zireael opened this issue Jun 22, 2019 · 4 comments

Comments

@Zireael
Copy link

Zireael commented Jun 22, 2019

Hi,
Not sure if I'm doing something wrong, but I'm testing Postgraphile with subscriptions and visualise through PostGraphiQL.
My query

subscription {
  somethings {
    edges {
      node {
        id
        string
      }}}}

executes correctly and I see correct data response. But when I create/update/delete a row, the changes do not get reflected in the PostGraphiQL response window.
The page says that the websocket connection is on:
image

Apologies, but I'm having hard time finding information on how to actually consume this subscription through postgraphile -> node(express) -> frontend (ie Axios, fetch etc). What chain of events (stack) would you use to deliver updated field value in database to user's browser html page?

Thanks in advance!

@benjie
Copy link
Member

benjie commented Jun 22, 2019

The documentation of our real-time features can be found here:

https://www.graphile.org/postgraphile/realtime/

It sounds like you’re referring to live queries, so you need to configure your database to support them.

@Zireael
Copy link
Author

Zireael commented Jun 22, 2019

Ah, thank you, you're right, I was using 'live' option rather than 'subscriptions'.
I've tried subscriptions too - do you mean for both live and subscription I need to set up subscription event in the database?
Nonetheless, the question remains - the changes in datablase don't get updated in PostgraphiQL 'live'.
My config for PostGraphiQL has

	graphiqlRoute: "/graphiql",
	graphiql: true, //!IS_PRODUCTION,
	enhanceGraphiql: true, //!IS_PRODUCTION
	live: true,

Now I'm trying to do the live queries in frontend through apollo-client, but I'm not getting any updates either.

const httpLink = new HttpLink({
  uri: "http://localhost:3000/graphql"
});
const graphql = new ApolloClient({
  link: httpLink,
  cache: new InMemoryCache(),
  connectToDevTools: true
});

const gquery = async (payload) => {
  const data = await graphql.query({ query: payload });
  console.log(data);
};

const sub = gql`subscription {
  somethings {
    edges {
      node {
        id
        string
      }}}}`

gquery(columns)

I guess I should be using some listener function?
Would you have an example frontend implementation of subscribing to a 'live' query?

Sorry for bothering you

@benjie
Copy link
Member

benjie commented Jun 22, 2019

Live queries require you to add a live adapter plugin and configure your database as said here:

https://www.graphile.org/postgraphile/live-queries/#graphilesubscriptions-lds

@benjie benjie transferred this issue from graphile/crystal Jun 23, 2019
@benjie
Copy link
Member

benjie commented Jun 23, 2019

Moved this issue to the documentation site since clearly we need to improve the documentation 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@benjie @Zireael and others