GraphQL

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

GraphQL
Developer(s)Meta, and community
Initial releaseSeptember 14, 2015 (2015-09-14)
Stable release
June 2018 (2018-06)[1]
Repositorygithub.com/graphql/graphql-spec
Written inImplementations in Java, JavaScript, Ruby, Scala, others.
Operating systemCross-platform
Websitegraphql.org

GraphQL is an open-source data query and manipulation language for APIs, and a runtime for fulfilling queries with existing data.[2] GraphQL was developed internally by Facebook (now Meta) in 2012 before being publicly released in 2015.[3] On 7 November 2018, the GraphQL project was moved from Facebook to the newly established GraphQL Foundation, hosted by the non-profit Linux Foundation.[4][5] Since 2012, GraphQL's rise has closely followed the adoption timeline as set out by Lee Byron, GraphQL's creator.[6] Byron's goal is to make GraphQL omnipresent across web platforms.

GraphQL provides an approach to developing web APIs and has been compared and contrasted with REST and other web service architectures. It allows clients to define the structure of the data required, and the same structure of the data is returned from the server. This prevents excessively large amounts of data from being returned, but can impede web caching of query results. The flexibility and richness of the query language also adds complexity that may not be worthwhile for simple APIs.[7][8][9] Despite the name, GraphQL does not provide the richness of graph operations that one might find in a full-fledged graph query language such as SPARQL, or even in dialects of SQL that support transitive closure. For example, a GraphQL interface that reports the parents of an individual cannot return, in a single query, the set of all their ancestors.

GraphQL consists of a type system, query language and execution semantics, static validation, and type introspection. It supports reading, writing (mutating), and subscribing to changes to data (realtime updates – most commonly implemented using Websockets).[10] GraphQL servers are available for multiple languages, including Haskell, JavaScript,[11] Perl,[12] Python,[13] Ruby, Java, C++,[14] C#, Scala, Go, Rust, Elixir,[15] Erlang, PHP, R, D[16] and Clojure. The result of a single query is returned in JSON format.

On 9 February 2018, the GraphQL Schema Definition Language (SDL) became part of the specification.[17]

Example[edit]

POST request:

{
    orders {
        id
        productsList {
            product {
                name
                price
            }
            quantity
        }
        totalAmount
    }
}

Response:

{
    "data": {
        "orders": [
            {
                "id": 1,
                "productsList": [
                    {
                        "product": {
                            "name": "orange",
                            "price": 1.5
                        },
                        "quantity": 100
                    }
                ],
                "totalAmount": 150
            }
        ]
    }
}

Testing[edit]

GraphQL APIs can be tested by triggering different requests at the API endpoint, and verifying the correctness of the response. This may be done manually by developers, or automated with testing tools. Tests may also be generated automatically. For example, a request triggered by an existing test case can be mutated to produce a variant,[18] and new requests may be produced through search-based techniques.[19] GraphQL requests arriving at the API endpoint in production may also be used to generate test cases that detect errors in the implementation of the schema.[20]

See also[edit]

References[edit]

  1. ^ "GraphQL June 2018 Release Notes". Retrieved 26 March 2019.
  2. ^ "GraphQL: A query language for APIs".
  3. ^ "GraphQL: A data query language". 14 September 2015.
  4. ^ "Facebook's GraphQL gets its own open-source foundation". TechCrunch. Retrieved 7 November 2018.
  5. ^ "The Linux Foundation Announces Intent to Form New Foundation to Support GraphQL - The Linux Foundation". The Linux Foundation. 6 November 2018. Retrieved 7 November 2018.
  6. ^ Anthony, Art (8 March 2018). "Is GraphQL Moving Toward Ubiquity?". NordicAPIs.
  7. ^ "GraphQL vs REST: Overview". Phil Sturgeon. Retrieved 25 November 2018.
  8. ^ "Why use GraphQL, good and bad reasons". Honest Engineering. 4 August 2018. Retrieved 26 November 2018.
  9. ^ "GraphQL Fundamentals". Howto GraphQL. Retrieved 4 July 2018.
  10. ^ "GraphQL". facebook.github.io. Facebook. Archived from the original on 18 July 2018. Retrieved 4 July 2018.
  11. ^ "GraphQL js". 16 October 2021.
  12. ^ "GraphQL - Perl implementation of GraphQL".
  13. ^ "Graphene". graphene-python.org. Retrieved 18 June 2017.
  14. ^ graphql/libgraphqlparser, GraphQL, 27 May 2020, retrieved 30 May 2020
  15. ^ "Absinthe: The GraphQL toolkit for Elixir". Retrieved 19 July 2018.
  16. ^ "Package graphqld on DUB".
  17. ^ "GraphQL SDL included in Github repository".
  18. ^ Vargas, D. M.; Blanco, A. F.; Vidaurre, A. C.; Alcocer, J. P. S.; Torres, M. M.; Bergel, A.; Ducasse, S. (2018). "Deviation Testing: A Test Case Generation Technique for GraphQL APIs". 11th International Workshop on Smalltalk Technologies (IWST): 1–9.
  19. ^ Karlsson, Stefan; Causevic, Adnan; Sundmark, Daniel (May 2021). "Automatic Property-based Testing of GraphQL APIs". 2021 IEEE/ACM International Conference on Automation of Software Test (AST). Madrid, Spain: IEEE: 1–10. doi:10.1109/AST52587.2021.00009. ISBN 978-1-6654-3567-3.
  20. ^ Zetterlund, Louise; Tiwari, Deepika; Monperrus, Martin; Baudry, Benoit (April 2022). "Harvesting Production GraphQL Queries to Detect Schema Faults". 2022 IEEE Conference on Software Testing, Verification and Validation (ICST). Valencia, Spain: IEEE: 365–376. doi:10.1109/ICST53961.2022.00014. ISBN 978-1-6654-6679-0.

External links[edit]