Url — GraphQL Custom Scalar

Author – ChilliCream

Date – 2026-01-05

1Overview

The Url scalar type represents a Uniform Resource Locator (URL) as defined by RFC 3986. It is intended for scenarios where a field must contain a valid URL, such as links to external resources, API endpoints, image sources, or any web-accessible resource.

Unlike the built-in String scalar which accepts any text, Url provides validation to ensure the value conforms to the URL specification.

3Result spec

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

A valid URL must include:

The URL may optionally include:

3.1Examples

These are valid result values:

Value Explanation
"https://example.com" Simple HTTPS URL.
"https://example.com/path/to/resource" URL with path.
"https://example.com:8080/api?key=value" URL with port and query string.
"ftp://files.example.com/document.pdf" FTP URL.
"https://example.com/page#section" URL with fragment.

These are invalid result values:

Value Why is it invalid
"not a url" Missing scheme and invalid format.
"//example.com" Missing scheme.
"http://" Missing authority/path.
"example.com" Missing scheme.
123 Must be a string, not a number.

4Input spec

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

Implementations should validate:

4.1Examples

Valid input values:

GraphQL Literal:

mutation {
  addBookmark(url: "https://example.com/article") {
    id
  }
}

JSON input:

{
  "url": "https://example.com/article"
}
{
  "imageSource": "https://cdn.example.com/images/photo.jpg"
}

Invalid input values:

Value Why is it invalid
"not a url" Missing scheme and invalid format.
"//example.com" Missing scheme.
"example.com" Missing scheme.
"http://" Missing authority/path.
"" Empty string.

5References

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