graphql-directive icon indicating copy to clipboard operation
graphql-directive copied to clipboard

Implementing a live directive

Open eljenso opened this issue 6 years ago • 2 comments

I'm trying to implement a live directive, which keeps the caller of the query up-to-date. This is my current code, which does just resolve() with the directive.

const typeDefs = /* GraphQL */ `
  directive @live on FIELD | FIELD_DEFINITION

  type Todo {
    text: String!
    completed: Boolean!
  }

  type Query {
    allTodos: [Todo]! @live
  }
`;

const resolvers = {
  Query: {
    allTodos() {
      return someTodoArray;
    }
  }
};

const executableSchema = makeExecutableSchema({
  typeDefs,
  resolvers
});

addDirectiveResolveFunctionsToSchema(executableSchema, {
  live(resolve) {
    return resolve();
  }
});

How would I push new results to the caller with this approach? Is there a way to get a reference to the caller to push new results?

eljenso avatar Apr 11 '18 12:04 eljenso

@eljenso : Hi, please trying to use new feature in graphql-tools, https://www.apollographql.com/docs/graphql-tools/schema-directives.html

giautm avatar Apr 20 '18 01:04 giautm

@giautm Thanks for the hint, will have a look.

eljenso avatar Apr 20 '18 09:04 eljenso