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

Implementing a live directive #9

Open
eljenso opened this issue Apr 11, 2018 · 2 comments
Open

Implementing a live directive #9

eljenso opened this issue Apr 11, 2018 · 2 comments

Comments

@eljenso
Copy link

eljenso commented Apr 11, 2018

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 eljenso changed the title Implement a live directive Implementing a live directive Apr 11, 2018
@giautm
Copy link

giautm commented Apr 20, 2018

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

@eljenso
Copy link
Author

eljenso commented Apr 20, 2018

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

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

2 participants