<?xml version="1.0" encoding="UTF-8"?>
<TEI xml:space="preserve" xmlns="http://www.tei-c.org/ns/1.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.tei-c.org/ns/1.0 https://raw.githubusercontent.com/kermitt2/grobid/master/grobid-home/schemas/xsd/Grobid.xsd"
 xmlns:xlink="http://www.w3.org/1999/xlink">
	<teiHeader xml:lang="en">
		<fileDesc>
			<titleStmt>
				<title level="a" type="main">An Empirical Analysis of GraphQL API Schemas in Open Code Repositories and Package Registries</title>
			</titleStmt>
			<publicationStmt>
				<publisher/>
				<availability status="unknown"><licence/></availability>
			</publicationStmt>
			<sourceDesc>
				<biblStruct>
					<analytic>
						<author>
							<persName><forename type="first">Yun</forename><forename type="middle">Wan</forename><surname>Kim</surname></persName>
							<email>timyun.kim@mail.utoronto.ca</email>
							<affiliation key="aff0">
								<orgName type="institution">University of Toronto</orgName>
								<address>
									<country key="CA">Canada</country>
								</address>
							</affiliation>
						</author>
						<author>
							<persName><forename type="first">Mariano</forename><forename type="middle">P</forename><surname>Consens</surname></persName>
							<email>consens@mie.utoronto.ca</email>
							<affiliation key="aff0">
								<orgName type="institution">University of Toronto</orgName>
								<address>
									<country key="CA">Canada</country>
								</address>
							</affiliation>
						</author>
						<author>
							<persName><forename type="first">Olaf</forename><surname>Hartig</surname></persName>
							<email>olaf.hartig@liu.se</email>
							<affiliation key="aff1">
								<orgName type="institution">Linköping University</orgName>
								<address>
									<country key="SE">Sweden</country>
								</address>
							</affiliation>
						</author>
						<title level="a" type="main">An Empirical Analysis of GraphQL API Schemas in Open Code Repositories and Package Registries</title>
					</analytic>
					<monogr>
						<imprint>
							<date/>
						</imprint>
					</monogr>
					<idno type="MD5">4972A60001AE5F817F6D11ED0500E4D3</idno>
				</biblStruct>
			</sourceDesc>
		</fileDesc>
		<encodingDesc>
			<appInfo>
				<application version="0.7.2" ident="GROBID" when="2023-03-25T02:45+0000">
					<desc>GROBID - A machine learning software for extracting information from scholarly documents</desc>
					<ref target="https://github.com/kermitt2/grobid"/>
				</application>
			</appInfo>
		</encodingDesc>
		<profileDesc>
			<abstract>
<div xmlns="http://www.tei-c.org/ns/1.0"><p>GraphQL is a query language for APIs that has been increasingly adopted by Web developers since its specification was open sourced in 2015. The GraphQL framework lets API clients tailor data requests by using queries that return JSON objects described using GraphQL Schema. We present initial results of an exploratory empirical study with the goal of characterizing GraphQL Schemas in open code repositories and package registries. Our first approach identifies over 20 thousand GraphQL-related projects in publicly accessible repositories hosted by GitHub. Our second, and complementary, approach uses package registries to find over 37 thousand dependent packages and repositories. In addition, over 2 thousand schema files were loaded into the GraphQL-JS reference implementation to conduct a detailed analysis of the schema information. Our study provides insights into the usage of different schema constructs, the number of distinct types and the most popular types in schemas, as well as the presence of cycles in schemas.</p></div>
			</abstract>
		</profileDesc>
	</teiHeader>
	<text xml:lang="en">
		<body>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="1">Motivation and Approach</head><p>The schema of a GraphQL API describes the data and the types of queries supported by the API. An empirical study of the GraphQL schemas used by open source projects, therefore, provides useful information about the characteristics of data interfaces. Currently, there is no comprehensive collection of such schemas or a tool that helps gather schemas from GraphQL APIs. The goal of the work presented in this paper is i) to establish a method to extract schemas into a single collection for analyses and ii) to conduct an empirical analysis of the schemas.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="1.1">Data Collection Method</head><p>APIs-guru has the most comprehensive list of public GraphQL APIs with links to endpoints and their documentation. By using APIs-guru, combined with manual effort through keyword searching, we collected 67 schemas of distinct APIs. Authentication requirements for most publicly available APIs hindered the efficiency and possible automation of schema extraction. Hence, we decided to take a different approach by extracting schemas from open source repositories from GitHub and used three sources to identify GraphQL repositories.</p><p>GitHub API As of June, 2018, there were more than 20,000 repositories on GitHub matching the keyword "graphql" and 2,000 repositories matching the keywords "graphql api".</p><p>Libraries.io API Decan et al. <ref type="bibr" target="#b0">[1]</ref> explored security vulnerabilities of NPM packages that were dependent on vulnerable packages. Following a similar method, we identified over 37,000 repositories dependent on GraphQL reference implementations.</p><p>GHTorrent Archived data of GHTorrent is hosted on Google's Big Query platform. We identified over 5,000 repositories matching the keyword "graphql". By using string search for schema for every repository file's full file-path, it was possible to identify exact path of potential schema files and their repository data. Our assumption is that this method returns a considerable portion of actual schemas available such that this portion is representative for the entire population of GraphQL schemas publicly availables. We found that schema files are most often named schema.json, schema.js, and schema.graphql for single-file schemas. For modular schemas, the files are most often separated by types, queries, mutations, and subscriptions but are contained in directories with the name schema or schemas.</p><p>After downloading all potential schema files, we tried to load each of them via GraphQL-JS. A successful attempt indicated a valid schema and a failure indicated an invalid schema or an irrelevant file. We identified duplicates through several methods including Levenshtein distance and cosine similarity.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2">Analysis Results</head><p>We identified a total of 2,777 valid but non-distinct schemas using the proposed method. 1,880 files were unique JSON-formatted schemas. We also conducted an exhaustive search excluding the "schema" keyword on all GraphQL-related repositories to collect a larger list of 3,949 schemas. The union of the two methods resulted in 4,095 schemas and, by using cosine similarity to filter duplicates, 2,081 schemas were unique. Figure <ref type="figure" target="#fig_0">1</ref> illustrates the number of schemas per source and the overlap of sources. This illustration shows that the different approaches to collect GraphQL schemas are non-redundant. To estimate our recall, we downloaded all .json and .graphql files from all repositories found with the keyword "graphql". By using the 3,949 valid schema counts, the estimated recall of our method is ca. 70% and the precision is 1.8%.</p><p>There are five major components of GraphQL schemas that describes the supported operations: Query, Object, Mutation, Subscription, and Directive. While every GraphQL server needs to support queries, which fetch information about data objects, other operations are not necessarily required. Only about 20% of the schemas have the Subscription type that can push information, while about 70% have the Mutation type via which the stored data can be changed. Object types dictate what information is exchanged between the users and the servers. We find that even after excluding scalar types and type definitions such as Query and Mutation, the most common types are generic types affiliated with reference implementations as shown in Table <ref type="table" target="#tab_3">4</ref>. Node is a reserved interface type for reference implementations such as Apollo and Relay with an identifier field and is the most common.</p><p>We traversed each schema in its JSON format recursively to identify their levels of nesting. We find that the median number of levels is 9 and the median number of levels only considering object types is 6. Excluding introspection and scalar type definitions, most schemas have only one level of nesting.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3">Cycles in GraphQL Schemas</head><p>Another interesting question is whether the relationships between the types in the schemas form directed cycles, because only if such cycles exist, the data exposed via a GraphQL API may contain directed cycles and these, in turn, may cause an undesired overhead during query processing <ref type="bibr" target="#b1">[2]</ref>.</p><p>Hence, we analyze GraphQL schemas as directed graphs. The vertices in such a graph for a given schema correspond to the object types, the interface types, and the union types in the schema. For every field definition whose value type is based on one such type, the graph contains an edge from the vertex that represents the type in which the field definition appears to the vertex that represents the value type of the field definition. Additionally, there are edges from interface types to their implementing object types and, similarly, from union types to their participating object types. In this paper we focus only on simple cycles; that is directed cycles in which repetition of vertices is not allowed.</p><p>For the analysis we use a program<ref type="foot" target="#foot_0">3</ref> that loads a schema, generates the corresponding graph representation of this schema, and then enumerates the simple cycles in the generated graph. For the latter step, the program applies a combination of Johnson's algorithm <ref type="bibr" target="#b2">[3]</ref> to enumerate the cycles and Tarjan's algorithm <ref type="bibr" target="#b3">[4]</ref> to first divide the graph into its strongly connected components, which is a prerequisite of Johnson's algorithm. To run the program for each of the 2,094 schemas we use an ordinary computer with 8 GB of RAM.</p><p>We find that 832 of the 2,094 schemas (39.7%) contain at least one simple cycle. For a more detailed analysis of these cycles we can, unfortunately, focus only on 788 of the 832 schemas; the other 44 schemas contain so many simple cycles (at least 10M in each of them) that enumerating these cycles causes the program to crash with an out-of-memory exception.</p><p>The distribution of the number of cycles in the remaining 788 schemas is illustrated in Figure <ref type="figure">2</ref>. As can be observed, the distribution resembles a power law. In more detail, 2 schemas contain more than 100K cycles (that is 0.3% of the 788 schemas), where the maximum is 256,348 cycles; 9 schemas contain more than 10K cycles (that is 1.1%); 41 schemas contain more than 1K cycles (5.2%); 73 contain more than 100 cycles (9.3%); 152 contain at least 10 cycles (19.3%), and 543 contain more than one cycle (68.9%). Hence, 31.1% contain exactly one cycle only.</p><p>Moreover, the average length of all cycles within each schema ranges from 2.0 to 20.5, but there is no correlation between this average length and the number of cycles. Similarly, we do not find a correlation between the number of cycles and the number of vertices or edges.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4">Concluding Remarks</head><p>This preliminary report describes our approach to collect and analyze thousands of GraphQL schemas from open project repositories. Initial descriptive and structural properties of the collected schemas were presented. The collection has also enabled additional analysis (not included in this contribution) such as temporal characteristics of repository commits and co-committer relationships.</p></div><figure xmlns="http://www.tei-c.org/ns/1.0" xml:id="fig_0"><head>Fig. 1 .</head><label>1</label><figDesc>Fig. 1. Number of schemas by sources. Fig. Number of cycles per schema.</figDesc><graphic coords="3,148.82,115.83,141.73,104.43" type="bitmap" /></figure>
<figure xmlns="http://www.tei-c.org/ns/1.0" type="table" xml:id="tab_0"><head>Table 1 .</head><label>1</label><figDesc>Summary of GraphQL repositories identified.</figDesc><table><row><cell>Method</cell><cell>NumRepositories</cell></row><row><cell>GitHub API</cell><cell>20,635</cell></row><row><cell>Libraries.io API</cell><cell>37,588</cell></row><row><cell>GHTorrent</cell><cell>5,188</cell></row></table></figure>
<figure xmlns="http://www.tei-c.org/ns/1.0" type="table" xml:id="tab_1"><head>Table 2 .</head><label>2</label><figDesc>Number of dependent repositories for the most popular implementations.</figDesc><table><row><cell>Package</cell><cell cols="2">language Count</cell></row><row><cell cols="3">NPM/graphql JavaScript 12,700</cell></row><row><cell>Pypi/graphene</cell><cell>Python</cell><cell>310</cell></row><row><cell cols="2">Rubygems/graphql Ruby</cell><cell>470</cell></row></table></figure>
<figure xmlns="http://www.tei-c.org/ns/1.0" type="table" xml:id="tab_2"><head>Table 3 .</head><label>3</label><figDesc>Number of non-empty components in the 2,081 schemas.</figDesc><table><row><cell cols="2">Schema components Frequency</cell></row><row><cell>object types</cell><cell>2,079</cell></row><row><cell>query type</cell><cell>2,079</cell></row><row><cell>directives</cell><cell>2,059</cell></row><row><cell>mutation type</cell><cell>1,440</cell></row><row><cell>subscription type</cell><cell>414</cell></row></table></figure>
<figure xmlns="http://www.tei-c.org/ns/1.0" type="table" xml:id="tab_3"><head>Table 4 .</head><label>4</label><figDesc>The ten most common object types.</figDesc><table><row><cell>Object type</cell><cell>Frequency</cell></row><row><cell>Node</cell><cell>1,009</cell></row><row><cell>PageInfo</cell><cell>922</cell></row><row><cell>User</cell><cell>879</cell></row><row><cell>UserConnection</cell><cell>336</cell></row><row><cell>UserEdge</cell><cell>307</cell></row><row><cell>BatchPayload</cell><cell>220</cell></row><row><cell>Viewer</cell><cell>215</cell></row><row><cell>UserPreviousValues</cell><cell>190</cell></row><row><cell>Post</cell><cell>182</cell></row></table></figure>
			<note xmlns="http://www.tei-c.org/ns/1.0" place="foot" n="3" xml:id="foot_0">https://github.com/LiUGraphQL/graphql-schema-cycles</note>
		</body>
		<back>

			<div type="acknowledgement">
<div xmlns="http://www.tei-c.org/ns/1.0"><p>Acknowledgements. The authors thank Jonas Lind and Kieron Soames who, as part of their thesis project at Linköping University, have developed the cycle enumeration program and applied it to our collection of schemas. Olaf Hartig's work on this paper has been funded by the CENIIT program at Linköping University (project no. 17.05).</p></div>
			</div>

			<div type="references">

				<listBibl>

<biblStruct xml:id="b0">
	<analytic>
		<title level="a" type="main">On the impact of security vulnerabilities in the npm package dependency network</title>
		<author>
			<persName><forename type="first">A</forename><surname>Decan</surname></persName>
		</author>
		<author>
			<persName><forename type="first">T</forename><surname>Mens</surname></persName>
		</author>
		<author>
			<persName><forename type="first">E</forename><surname>Constantinou</surname></persName>
		</author>
		<idno type="DOI">10.1145/3196398.3196401</idno>
		<ptr target="http://doi.acm.org/10.1145/3196398.3196401" />
	</analytic>
	<monogr>
		<title level="m">Proceedings of the 15th International Conference on Mining Software Repositories</title>
				<meeting>the 15th International Conference on Mining Software Repositories</meeting>
		<imprint>
			<date type="published" when="2018">2018</date>
			<biblScope unit="volume">18</biblScope>
			<biblScope unit="page" from="181" to="191" />
		</imprint>
	</monogr>
</biblStruct>

<biblStruct xml:id="b1">
	<analytic>
		<title level="a" type="main">Semantics and Complexity of GraphQL</title>
		<author>
			<persName><forename type="first">O</forename><surname>Hartig</surname></persName>
		</author>
		<author>
			<persName><forename type="first">J</forename><surname>Pérez</surname></persName>
		</author>
		<idno type="DOI">10.1145/3178876.3186014</idno>
		<ptr target="https://doi.org/10.1145/3178876.3186014" />
	</analytic>
	<monogr>
		<title level="m">Proceedings of the 2018 World Wide Web Conference</title>
				<meeting>the 2018 World Wide Web Conference<address><addrLine>Republic and Canton of Geneva, Switzerland</addrLine></address></meeting>
		<imprint>
			<date type="published" when="2018">2018</date>
			<biblScope unit="page" from="1155" to="1164" />
		</imprint>
	</monogr>
	<note>WWW &apos;18</note>
</biblStruct>

<biblStruct xml:id="b2">
	<analytic>
		<title level="a" type="main">Finding all the elementary circuits of a directed graph</title>
		<author>
			<persName><forename type="first">D</forename><forename type="middle">B</forename><surname>Johnson</surname></persName>
		</author>
		<idno type="DOI">10.1137/0204007</idno>
		<ptr target="https://doi.org/10.1137/0204007" />
	</analytic>
	<monogr>
		<title level="j">SIAM J. Comput</title>
		<imprint>
			<biblScope unit="volume">4</biblScope>
			<biblScope unit="issue">1</biblScope>
			<biblScope unit="page" from="77" to="84" />
			<date type="published" when="1975">1975</date>
		</imprint>
	</monogr>
</biblStruct>

<biblStruct xml:id="b3">
	<analytic>
		<title level="a" type="main">Depth-first search and linear graph algorithms</title>
		<author>
			<persName><forename type="first">R</forename><forename type="middle">E</forename><surname>Tarjan</surname></persName>
		</author>
		<idno type="DOI">10.1137/0201010</idno>
		<ptr target="https://doi.org/10.1137/0201010" />
	</analytic>
	<monogr>
		<title level="j">SIAM J. Comput</title>
		<imprint>
			<biblScope unit="volume">1</biblScope>
			<biblScope unit="issue">2</biblScope>
			<biblScope unit="page" from="146" to="160" />
			<date type="published" when="1972">1972</date>
		</imprint>
	</monogr>
</biblStruct>

				</listBibl>
			</div>
		</back>
	</text>
</TEI>
