Skip to content

Add Schema Coordinates functions documentation #998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: source
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/content/graphql-js/APIReference-Language.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ layout: docs
category: API Reference
permalink: /graphql-js/language/
sublinks: BREAK,getLocation,Kind,lex,parse,parseValue,printSource,visit
next: /graphql-js/type/
next: /graphql-js/schema-coordinates/
---

The `graphql/language` module is responsible for parsing and operating on the GraphQL language. You can import either from the `graphql/language` module, or from the root `graphql` module. For example:
Expand Down
87 changes: 87 additions & 0 deletions src/content/graphql-js/APIReference-SchemaCoordinates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
title: graphql/schema-coordinates
layout: docs
category: API Reference
permalink: /graphql-js/schema-coordinates/
sublinks: parseSchemaCoordinate,printSchemaCoordinate,nodeFromSchemaCoordinate,schemaCoordinateFromNode
next: /graphql-js/type/
---

The `graphql/schema-coordinates` module is responsible for parsing and working with Schema Coordinates. You can import either from the `graphql/schema-coordinates` module, or from the root `graphql` module. For example:

```js
import { SchemaCoordinates } from 'graphql'; // ES6
var { SchemaCoordinates } = require('graphql'); // CommonJS
```

## Overview

<ul class="apiIndex">
<li>
<a href="#parseSchemaCoordinate">
<pre>function parseSchemaCoordinate</pre>
Parses a Schema Coordinate string according to the Schema Coordinate Grammar
</a>
</li>
<li>
<a href="#printSchemaCoordinate">
<pre>function printSchemaCoordinate</pre>
Prints a Schema Coordinate string from its AST
</a>
</li>
<li>
<a href="#nodeFromSchemaCoordinate">
<pre>function nodeFromSchemaCoordinate</pre>
Returns a GraphQL AST node from its Schema Coordinate and Schema
</a>
</li>
<li>
<a href="#schemaCoordinateFromNode">
<pre>function schemaCoordinateFromNode</pre>
Returns the Schema Coordinate of a GraphQL Schema AST node
</a>
</li>
</ul>

## SchemaCoordinates

### parseSchemaCoordinate

```js
function parseSchemaCoordinate(schemaCoordinate: string): SchemaCoordinateAST
```

Takes a Schema Coordinate as a string, and returns its corresponding AST
representation.

### printSchemaCoordinate

```js
function printSchemaCoordinate(schemaCoordinateAST: SchemaCoordinateAST): string
```

Serializes a Schema Coordinate AST back into a Schema Coordinate string.

### nodeFromSchemaCoordinate

```js
function nodeFromSchemaCoordinate(
schemaCoordinate: string,
schema: GraphQLSchema,
): ?ASTNode // TODO: Define some subset of ASTNode that Schema Coordinates can represent
```

Takes a Schema Coordinate and a GraphQLSchema and returns the AST node of the
corresponding type, field, argument, enum value, or directive in the Schema.

### schemaCoordinateFromNode

```js
function schemaCoordinateFromNode(
// TODO: confirm we can walk up the tree with an ASTNode (such that we don't need a GraphQLSchema as an argument too)
node: ASTNode,
): ?string
```

Takes a GraphQL Schema AST Node and returns its Schema Coordinate string
representation.