freearhey / wikigraph

GraphQL API for quick access to Wikidata

Home Page:https://wikigraph.vercel.app/graphql

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WikiGraph

GraphQL API for quick access to Wikidata.

Usage

GraphQL IDE

https://wikigraph.vercel.app/graphql

cURL

curl \
-X POST \
-H "Content-Type: application/json" \
--data '{ "query": "{ entity(id: \"Q2\") { id, label, description } }" }' \
https://wikigraph.vercel.app/graphql

JavaScript

fetch('https://wikigraph.vercel.app/graphql', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    query: `
      query { 
        entity(id: "Q2") { 
           id, 
           label,
           description 
        } 
     }`
  })
})
  .then(response => response.json())
  .then(json => console.log(json.data))

Supported Operations

search

Searches for entities using labels.

Arguments:

  • query - term to search (required)
  • lang - language to use for property values (default: 'en')
  • first - maximal number of results (default: 10)
  • offset - offset where to continue a search (default: 0)

Example:

{
  search(query: "Earth", lang: "fr", first: 1) {
    id
    label
    description
  }
}

Response:

{
  "data": {
    "search": [
      {
        "id": "Q982498",
        "label": "Earth",
        "description": "ville américaine de l'état du Texas"
      }
    ]
  }
}

entity

Lookup an entity by ID.

Arguments:

  • id - the ID of the entity to get the data from (required)
  • lang - language to use for property values (default: 'en')

Example:

{
  entity(id: "Q2", lang: "de") {
    id
    label
    description
  }
}

Response:

{
  "data": {
    "entity": {
      "id": "Q2",
      "label": "Erde",
      "description": "dritter Planet von der Sonne aus im Sonnensystem"
    }
  }
}

Available Properties

You can get the value of any Wikidata property by its slug. For example query:

{
  entity(id: "Q2") {
    instance_of
  }
}

will produce the following JSON response:

{
  "data": {
    "entity": {
      "instance_of": ["inner planet"]
    }
  }
}

If the object has no such property, the value will be an empty array.

Contribution

If you find a bug or want to contribute to the code or documentation, you can help by submitting an issue or a pull request.

License

MIT

About

GraphQL API for quick access to Wikidata

https://wikigraph.vercel.app/graphql

License:MIT License


Languages

Language:JavaScript 100.0%