GraphQL in VG

GraphQL: A graph oriented way to think about and explore data

[without the data actually having to be in
a graph database any particular structure,
database or format at all]

The good parts

  • No more front ↔ back end data dependencies 
  • Easier to avoid over/under fetching 
  • Clean abstraction of data backends

The bad tricky parts

  • Avoiding dangerous/expensive queries

Example #1

Basic article information

query Query {
  article(id:196000) {
    id
    title
    authors {
      name
    }
  }
}
{
  "data": {
    "article": {
      "id": 196000,
      "title": "Slik kan nettbankene bli sikrere",
      "authors": [
        {
          "name": "Pål Unanue-Zahl"
        },
        {
          "name": "Madeleine Bråthen Bjaaland"
        }
      ]
    }
  }
}

Example #2

Article with tags and categories

query Query {
  article(id:196000) {
    id
    title
    preamble
    story
    authors { name }
    tags { id name }
    categories { id name }
  }
}
{
  "data": {
    "article": {
      "id": 196000,
      "title": "Slik kan nettbankene bli sikrere",
      "preamble": "...",
      "story": "<p>De kan virke...",
      "authors": [
        {
          "name": "Pål Unanue-Zahl"
        },
        {
          "name": "Madeleine Bråthen Bjaaland"
        }
      ],
      "tags": [
        {
          "id": 1434,
          "name": "Datasikkerhet"
        },
        {
          "id": 1433,
          "name": "Datakriminalitet"
        },
        {
          "id": 1430,
          "name": "Data og nett"
        }
      ],
      "categories": [
        {
          "id": 1107,
          "name": "Teknologi"
        },
        {
          "id": 1102,
          "name": "Forbruker"
        }
      ]
    }
  }
}

Example #3

Tags/category listings

query Query {
  tag(id:1) {
    id
    name
    articles {
      id
      title
    }
  }
}
{
  "data": {
    "tag": {
      "id": 1,
      "name": "Statoil",
      "articles": [
        {
          "id": 8042902,
          "title": "800 millioner kroner til Statoil-meklere"
        },
        {
          "id": 6738410,
          "title": "Applaus for Statoil-aksjen"
        },
        {
          "id": 8159735,
          "title": "69 kroner for Statoil-aksjen"
        },
        ...
      ]
    }
  }
}

Why is it a good fit for VG?

  • Data available for everyone
     
  • New entities can be made available by the people who know the data and used by anybody. Without having to know or read up on DrLib, Solr or Phoenix APIs.
     
  • Our requirements change over time. GraphQL is built for this. Facebook is serving over 2000 versions of their mobile apps with data, from the same endpoint.

This is EntityLib

Where do we stand?

  • Initial version got it's data from Jaris ElasticSearch index and the newsroom API
     
  • Rewrite to fetch all the data from DrLib is close to finished, without a single change visible to the end user. Nice.
     
  • Next steps is sanity checks for queries (depth, size and possibly cost) and adding more connected data such as widgets, ads and stuff.
Made with Slides.com