Giter Club home page Giter Club logo

wp-graphql-polls's Introduction

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 here.

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
  }
}
  • The integer id is unique identifier for the poll you are voting.
  • The integer userId is the identifier of the voter.
  • The string answers are the ids of the user selected answers. Note: they have to be comma separated only.

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
    }
  }
}
  • id: (integer) is the unique identifier for the poll you are voting.
  • question: (string) is a text describing the poll.
  • totalVotes: (integer) is the total amount of votes in this poll.
  • open: (boolean) is the current status of the poll. Telling either if it's available for voting or not.
  • maxAnswers: (integer) is the number of answers that can be selected per user before voting.
  • voted: (boolean) tells if the user has already voted in this poll.
  • answers: (array) is an array of object containing detailed information about the poll's options.
    • id: (integer) is the unique identifier for the respective answer.
    • description: (string) is a text representing an option for voting.
    • votes: (integer) is the unique identifier for the poll you are voting.

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:

  • 201: Created
  • 400: Bad Request
  • 401: Unauthorized
  • 403: Forbidden
  • 409: Conflict
  • 500: Internal Server Error

Thanks

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

wp-graphql-polls's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.