GraphQL OneOf Input

GraphQL OneOf 입력

A @oneOf input object accepts exactly one provided, non-null choice.

···
html
<div class="viz"><h3>input FindUser @oneOf</h3><div class="row"><div class="box code" id="payload">{ id: 42 }</div><span class="arrow">→</span><div class="box" id="verdict">VALID</div></div><div class="muted" id="reason">exactly one non-null field</div></div>
css
.viz{width:94%;height:88%;max-width:960px;padding:clamp(10px,2vmin,18px);border:1px solid var(--line);border-radius:14px;background:var(--surface);font:600 clamp(12px,1.35vw,16px)/1.35 var(--font-sans,system-ui,sans-serif);display:flex;flex-direction:column;gap:clamp(7px,1.8vmin,13px);overflow:hidden}.viz h3{margin:0;color:var(--accent);font:700 clamp(12px,1.35vw,16px)/1.2 var(--font-sans,system-ui,sans-serif);letter-spacing:.04em}.viz .row{display:flex;align-items:center;justify-content:center;gap:clamp(5px,1.4vmin,12px);flex:1;min-height:0}.viz .box{padding:clamp(5px,1.5vmin,12px);border:1px solid var(--line);border-radius:9px;background:var(--bg);text-align:center}.viz .muted{color:var(--muted)}.viz .accent{color:var(--accent)}.viz .code{font-family:ui-monospace,monospace}.viz .pill{padding:3px 7px;border:1px solid var(--line);border-radius:99px;white-space:nowrap}.viz .active{border-color:var(--accent);background:color-mix(in srgb,var(--accent) 12%,var(--surface))}.viz .arrow{color:var(--accent);font:700 18px ui-monospace,monospace}#payload{min-width:51%}#verdict{min-width:20%;border-color:var(--accent)}#verdict.invalid{color:var(--accent-3);border-color:var(--accent-3)}
js
const cases=[['{ id: 42 }','VALID','exactly one non-null field'],['{ id: 42, username: "ada" }','ERROR','two fields supplied'],['{ username: "ada" }','VALID','exactly one non-null field']];let i=0;function draw(){const c=cases[i];document.getElementById('payload').textContent=c[0];const v=document.getElementById('verdict');v.textContent=c[1];v.classList.toggle('invalid',c[1]==='ERROR');document.getElementById('reason').textContent=c[2];i=(i+1)%cases.length}draw();setInterval(draw,1500)

A GraphQL OneOf input object expresses a choice among several alternatives in the schema. For example, a lookup may accept either an ID or a username; sending both or neither is invalid. The chosen field must also be non-null.

The demo passes an ID-only input and rejects a pair of ID and username. The schema fields are nullable types, while a valid submitted object must contain exactly one non-null value.

When to use

Use it when one argument must choose among mutually exclusive lookup or search keys.

Open as page ↗