Skip to content

Commit 0c651f8

Browse files
authored
Add ChilliCream URI scalar (#64)
1 parent ee6e007 commit 0c651f8

File tree

1 file changed

+132
-0
lines changed
  • scalars/contributed/chillicream

1 file changed

+132
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# URI — GraphQL Custom Scalar
2+
3+
Author – ChilliCream
4+
5+
Date – 2026-02-16
6+
7+
**License and Copyright**
8+
9+
Copyright © GraphQL contributors. This specification is licensed under
10+
[OWFa 1.0](https://www.openwebfoundation.org/the-agreements/the-owf-1-0-agreements-granted-claims/owfa-1-0).
11+
12+
# Overview
13+
14+
The `URI` scalar type represents a Uniform Resource Identifier (URI) as defined
15+
by RFC 3986. It is intended for scenarios where a field must contain a valid
16+
URI, which includes both URLs (locators) and URNs (names), such as resource
17+
identifiers, namespace identifiers, or any standardized resource reference.
18+
19+
Unlike the `URL` scalar which specifically requires a locator with a scheme and
20+
hierarchical structure, `URI` accepts the broader set of URI formats including
21+
relative references and URNs. Unlike the built-in `String` scalar which accepts
22+
any text, `URI` provides validation to ensure the value conforms to the URI
23+
specification.
24+
25+
# Recommended name
26+
27+
The recommended name for this scalar is `URI`.
28+
29+
# Result spec
30+
31+
A `URI` scalar must serialize to a string representation of a valid URI
32+
conforming to RFC 3986.
33+
34+
A valid URI may be:
35+
36+
- An absolute URI with scheme (e.g., `https://example.com`,
37+
`urn:isbn:0451450523`)
38+
- A relative reference (e.g., `/path/to/resource`, `../parent/resource`)
39+
- A URI with optional authority, path, query, and fragment components
40+
41+
## Examples
42+
43+
These are valid result values:
44+
45+
| Value | Explanation |
46+
| ------------------------------------------ | --------------------------------- |
47+
| `"https://example.com"` | Absolute HTTP URL. |
48+
| `"urn:isbn:0451450523"` | URN for an ISBN. |
49+
| `"/path/to/resource"` | Relative reference with path. |
50+
| `"//example.com/path"` | Protocol-relative reference. |
51+
| `"../parent/resource"` | Relative reference with parent. |
52+
| `"https://example.com:8080/api?key=value"` | Absolute URL with port and query. |
53+
| `"mailto:user@example.com"` | Mailto URI. |
54+
| `"#section"` | Fragment-only reference. |
55+
| `"?query=value"` | Query-only reference. |
56+
57+
These are invalid result values:
58+
59+
| Value | Why is it invalid |
60+
| ----------------------- | ------------------------------- |
61+
| `"ht!tp://example.com"` | Invalid scheme characters. |
62+
| `"http://exam ple.com"` | Contains whitespace. |
63+
| `123` | Must be a string, not a number. |
64+
65+
# Input spec
66+
67+
A `URI` scalar accepts string values representing valid URIs conforming to RFC
68+
3986, both as GraphQL literals and as JSON input values.
69+
70+
Implementations should validate:
71+
72+
- String is a valid URI per RFC 3986
73+
- String does not contain invalid characters (e.g., unescaped spaces)
74+
- String follows proper URI syntax rules
75+
76+
Note: Unlike the `URL` scalar, `URI` accepts both absolute and relative
77+
references, making it suitable for a broader range of use cases.
78+
79+
## Examples
80+
81+
Valid input values:
82+
83+
GraphQL Literal:
84+
85+
```graphql
86+
mutation {
87+
createResource(uri: "urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6") {
88+
id
89+
}
90+
}
91+
```
92+
93+
```graphql
94+
mutation {
95+
addLink(uri: "/relative/path/to/resource") {
96+
id
97+
}
98+
}
99+
```
100+
101+
JSON input:
102+
103+
```json
104+
{
105+
"uri": "https://example.com/article"
106+
}
107+
```
108+
109+
```json
110+
{
111+
"resourceId": "urn:isbn:0451450523"
112+
}
113+
```
114+
115+
```json
116+
{
117+
"relativeUrl": "../parent/page"
118+
}
119+
```
120+
121+
Invalid input values:
122+
123+
| Value | Why is it invalid |
124+
| ----------------------- | ------------------------------ |
125+
| `"ht!tp://example.com"` | Invalid scheme characters. |
126+
| `"http://exam ple.com"` | Contains unescaped whitespace. |
127+
| `""` | Empty string. |
128+
129+
# References
130+
131+
- [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986) — Uniform Resource
132+
Identifier (URI): Generic Syntax

0 commit comments

Comments
 (0)