URI — GraphQL Custom Scalar

Author – ChilliCream

Date – 2026-02-16

1Overview

The URI scalar type represents a Uniform Resource Identifier (URI) as defined by RFC 3986. It is intended for scenarios where a field must contain a valid URI, which includes both URLs (locators) and URNs (names), such as resource identifiers, namespace identifiers, or any standardized resource reference.

Unlike the URL scalar which specifically requires a locator with a scheme and hierarchical structure, URI accepts the broader set of URI formats including relative references and URNs. Unlike the built-in String scalar which accepts any text, URI provides validation to ensure the value conforms to the URI specification.

3Result spec

A URI scalar must serialize to a string representation of a valid URI conforming to RFC 3986.

A valid URI may be:

3.1Examples

These are valid result values:

Value Explanation
"https://example.com" Absolute HTTP URL.
"urn:isbn:0451450523" URN for an ISBN.
"/path/to/resource" Relative reference with path.
"//example.com/path" Protocol-relative reference.
"../parent/resource" Relative reference with parent.
"https://example.com:8080/api?key=value" Absolute URL with port and query.
"mailto:[email protected]" Mailto URI.
"#section" Fragment-only reference.
"?query=value" Query-only reference.

These are invalid result values:

Value Why is it invalid
"ht!tp://example.com" Invalid scheme characters.
"http://exam ple.com" Contains whitespace.
123 Must be a string, not a number.

4Input spec

A URI scalar accepts string values representing valid URIs conforming to RFC 3986, both as GraphQL literals and as JSON input values.

Implementations should validate:

Note Unlike the URL scalar, URI accepts both absolute and relative references, making it suitable for a broader range of use cases.

4.1Examples

Valid input values:

GraphQL Literal:

mutation {
  createResource(uri: "urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6") {
    id
  }
}
mutation {
  addLink(uri: "/relative/path/to/resource") {
    id
  }
}

JSON input:

{
  "uri": "https://example.com/article"
}
{
  "resourceId": "urn:isbn:0451450523"
}
{
  "relativeUrl": "../parent/page"
}

Invalid input values:

Value Why is it invalid
"ht!tp://example.com" Invalid scheme characters.
"http://exam ple.com" Contains unescaped whitespace.
"" Empty string.

5References

  1. 1Overview
  2. 2Recommended name
  3. 3Result spec
    1. 3.1Examples
  4. 4Input spec
    1. 4.1Examples
  5. 5References