Home

Awesome

wp-graphql-logo-image

WPGraphQL Polls

This plugin extends the WPGraphQL & WP-Polls plugins and provide the interface for consuming the WP-Polls through queries and mutations.

This plugin is possible because of the work of Adrien Becuwe & 7aduta. Please, don't forget to checkout their respective work.

Wp-Polls Rest Api by Adrien Becuwe

Wp-Polls Rest Api by 7aduta

Install, Activate & Setup

You can install and activate the plugin like any WordPress plugin. Download the .zip from Github and add to your plugins directory, then activate.

It requires you to have WP-Polls plugin first in order to work. You can get it <a href="https://github.com/lesterchan/wp-polls" target="_blank">here</a>.

Voting

This plugin adds a new vote mutation to the WPGraphQL Schema.

This can be used like so:

mutation PollVote {
  vote(input: {
    clientMutationId: "Vote",
    id: 1,
    userId: 1,
    answers: "1,2,3"
  }) {
    status
    message
  }
}

It returns a status code and a respective message after the operation has been executed or not.

Querying

You can query polls by doing the following query:

query GetAllPolls {
  polls {
    id
    question
    totalVotes
    open
    maxAnswers
    voted
    answers {
      id
      description
      votes
    }
  }
}

If you need to query an specific poll you can do it by passing the poll id through the query, like the example bellow:

query GetPollById {
  polls(id: 1) {
    ...
  }
}

Status

The statuses returned by the vote mutation are normal HTTP codes. The ones used in this plugin are:

Thanks

I'd like to say many thanks to WPGraphQL, Lester Chan, Adrien Becuwe & 7aduta for their work.