1"use strict";(self.webpackChunk=self.webpackChunk||[]).push([["12296"],{65923(e,n,t){t.r(n),t.d(n,{metadata:()=>s,default:()=>p,frontMatter:()=>c,contentTitle:()=>l,toc:()=>h,assets:()=>d});var s=JSON.parse('{"id":"debugging/inconsistent-typename-error","title":"Inconsistent Typename Error","description":"Debugging inconsistent typename errors in Relay","source":"@site/versioned_docs/version-v18.0.0/debugging/inconsistent-typename-error.md","sourceDirName":"debugging","slug":"/debugging/inconsistent-typename-error/","permalink":"/docs/v18.0.0/debugging/inconsistent-typename-error/","draft":false,"unlisted":false,"editUrl":"https://github.com/facebook/relay/tree/main/website/versioned_docs/version-v18.0.0/debugging/inconsistent-typename-error.md","tags":[],"version":"v18.0.0","frontMatter":{"id":"inconsistent-typename-error","title":"Inconsistent Typename Error","slug":"/debugging/inconsistent-typename-error/","description":"Debugging inconsistent typename errors in Relay","keywords":["debugging","troubleshooting","inconsistent typename","RelayResponseNormalizer","globally unique id"]},"sidebar":"docs","previous":{"title":"Relay DevTools","permalink":"/docs/v18.0.0/debugging/relay-devtools/"},"next":{"title":"Debugging Declarative Mutation Directives","permalink":"/docs/v18.0.0/debugging/declarative-mutation-directives/"}}'),i=t(74848),o=t(28453),r=t(86898),a=t(17352);let c={id:"inconsistent-typename-error",title:"Inconsistent Typename Error",slug:"/debugging/inconsistent-typename-error/",description:"Debugging inconsistent typename errors in Relay",keywords:["debugging","troubleshooting","inconsistent typename","RelayResponseNormalizer","globally unique id"]},l,d={},h=[{value:"Inconsistent <code>__typename</code> error",id:"inconsistent-__typename-error",level:2},{value:"Common cause",id:"common-cause",level:2},{value:"Fix: Make your type spec compliant",id:"fix-make-your-type-spec-compliant",level:2},{value:"Example",id:"example",level:3}];function u(e){let n={a:"a",blockquote:"blockquote",code:"code",h2:"h2",h3:"h3",p:"p",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(n.h2,{id:"inconsistent-__typename-error",children:["Inconsistent ",(0,i.jsx)(n.code,{children:"__typename"})," error"]}),"\n",(0,i.jsx)(n.p,{children:"The GraphQL server likely violated the globally unique ID requirement by returning the same ID for different objects."}),"\n",(0,i.jsx)(n.p,{children:"If you're seeing an error like:"}),"\n",(0,i.jsxs)(n.blockquote,{children:["\n",(0,i.jsx)(n.p,{children:(0,i.jsx)(n.code,{children:"RelayResponseNormalizer: Invalid record '543'. Expected __typename to be consistent, but the record was assigned conflicting types Foo and Bar. The GraphQL server likely violated the globally unique ID requirement by returning the same ID for different objects."})}),"\n"]}),"\n",(0,i.jsxs)(n.p,{children:["the server implementation of one of the types is not spec compliant. We require the ",(0,i.jsx)(n.code,{children:"id"})," field to be globally unique. This is a problem because Relay stores objects in a normalized key-value store and one of the object just overwrote the other. This means your app is broken in some subtle or less subtle way."]}),"\n",(0,i.jsx)(n.h2,{id:"common-cause",children:"Common cause"}),"\n",(0,i.jsxs)(n.p,{children:["The most common reason for this error is that 2 objects backed by an ID are using the plain ID as the id field, such as a ",(0,i.jsx)(n.code,{children:"User"})," and ",(0,i.jsx)(n.code,{children:"MessagingParticipant"}),"."]}),"\n",(0,i.jsx)(n.p,{children:"Less common reasons could be using array indices or auto-increment IDs from some database that might not be unique to this type."}),"\n",(0,i.jsx)(n.h2,{id:"fix-make-your-type-spec-compliant",children:"Fix: Make your type spec compliant"}),"\n",(0,i.jsxs)(n.p,{children:["The best way to fix this is to make your type spec compliant. For the case of 2 different types backed by the same ID, a common solution is to prefix the ID of the less widely used type with a unique string and then base64 encode the result. This can be accomplished fairly easily by implementing a ",(0,i.jsx)(n.code,{children:"NodeTokenResolver"})," using the helper trait ",(0,i.jsx)(n.code,{children:"NodeTokenResolverWithPrefix"}),". When the ",(0,i.jsx)(n.code,{children:"NodeTokenResolver"})," is registered is allows you to load your type using ",(0,i.jsx)(n.code,{children:"node(id: $yourID)"}
1)," GraphQL call and your type can return an encoded ID."]}),"\n",(0,i.jsxs)(a.FbInternalOnly,{children:[(0,i.jsx)(n.h3,{id:"example",children:"Example"}),(0,i.jsxs)(n.p,{children:["See ",(0,i.jsx)(n.a,{href:"https://www.internalfb.com/diff/D17996531",children:"D17996531"})," for an example on how to fix this. It created a ",(0,i.jsx)(n.code,{children:"FusionPlatformComponentsCategoryNodeResolver"})," added the trait ",(0,i.jsx)(n.code,{children:"TGraphQLNodeMixin"})," to the conflicting class so that it generates the base64 encoded ID."]})]}),"\n",(0,i.jsx)(r.A,{})]})}function p(e={}){let{wrapper:n}={...(0,o.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(u,{...e})}):u(e)}},86898(e,n,t){t.d(n,{A:()=>m});var s=t(74848),i=t(95310),o=t(17352),r=t(96540);function a(){let e=window.encodeURI(JSON.stringify({title:"Feedback about "+window.location.pathname,description:"**!!! Required !!!**\n\nPlease modify the task description to let us know how the docs can be improved.\n\n**Please do not ask support questions via this form! Instead, ask in fburl.com/relay_support**",tag_ids:{add:[0xac96423e5b680,0x64079768ac750]}}));window.open("https://www.internalfb.com/tasks/?n="+e)}function c({children:e}){return(0,s.jsxs)("div",{className:"docsRating",id:"docsRating",children:[(0,s.jsx)("hr",{}),e]})}let l=()=>{let[e,n]=r.useState(!1),t=e=>{n(!0),window.ga&&window.ga("send",{hitType:"event",eventCategory:"button",eventAction:"feedback",eventValue:e})};return e?"Thank you for letting us know!":(0,s.jsxs)(s.Fragment,{children:["Is this page useful?",(0,s.jsx)("svg",{className:"i_thumbsup",alt:"Like",id:"docsRating-like",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 81.13 89.76",onClick:()=>t(1),children:(0,s.jsx)("path",{d:"M22.9 6a18.57 18.57 0 002.67 8.4 25.72 25.72 0 008.65 7.66c3.86 2 8.67 7.13 13.51 11 3.86 3.11 8.57 7.11 11.54 8.45s13.59.26 14.64 1.17c1.88 1.63 1.55 9-.11 15.25-1.61 5.86-5.96 10.55-6.48 16.86-.4 4.83-2.7 4.88-10.93 4.88h-1.35c-3.82 0-8.24 2.93-12.92 3.62a68 68 0 01-9.73.5c-3.57 0-7.86-.08-13.25-.08-3.56 0-4.71-1.83-4.71-4.48h8.42a3.51 3.51 0 000-7H12.28a2.89 2.89 0 01-2.88-2.88 1.91 1.91 0 01.77-1.78h16.46a3.51 3.51 0 000-7H12.29c-3.21 0-4.84-1.83-4.84-4a6.41 6.41 0 011.17-3.78h19.06a3.5 3.5 0 100-7H9.75A3.51 3.51 0 016 42.27a3.45 3.45 0 013.75-3.48h13.11c5.61 0 7.71-3 5.71-5.52-4.43-4.74-10.84-12.62-11-18.71-.15-6.51 2.6-7.83 5.36-8.56m0-6a6.18 6.18 0 00-1.53.2c-6.69 1.77-10 6.65-9.82 14.5.08 5.09 2.99 11.18 8.52 18.09H9.74a9.52 9.52 0 00-6.23 16.9 12.52 12.52 0 00-2.07 6.84 9.64 9.64 0 003.65 7.7 7.85 7.85 0 00-1.7 5.13 8.9 8.9 0 005.3 8.13 6 6 0 00-.26 1.76c0 6.37 4.2 10.48 10.71 10.48h13.25a73.75 73.75 0 0010.6-.56 35.89 35.89 0 007.58-2.18 17.83 17.83 0 014.48-1.34h1.35c4.69 0 7.79 0 10.5-1 3.85-1.44 6-4.59 6.41-9.38.2-2.46 1.42-4.85 2.84-7.62a41.3 41.3 0 003.42-8.13 48 48 0 001.59-10.79c.1-5.13-1-8.48-3.35-10.55-2.16-1.87-4.64-1.87-9.6-1.88a46.86 46.86 0 01-6.64-.29c-1.92-.94-5.72-4-8.51-6.3l-1.58-1.28c-1.6-1.3-3.27-2.79-4.87-4.23-3.33-3-6.47-5.79-9.61-7.45a20.2 20.2 0 01-6.43-5.53 12.44 12.44 0 01-1.72-5.36 6 6 0 00-6-5.86z"})}),(0,s.jsx)("svg",{className:"i_thumbsdown",alt:"Dislike",id:"docsRating-dislike",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 81.13 89.76",onClick:()=>t(0),children:(0,s.jsx)("path",{d:"M22.9 6a18.57 18.57 0 002.67 8.4 25.72 25.72 0 008.65 7.66c3.86 2 8.67 7.13 13.51 11 3.86 3.11 8.57 7.11 11.54 8.45s13.59.26 14.64 1.17c1.88 1.63 1.55 9-.11 15.25-1.61 5.86-5.96 10.55-6.48 16.86-.4 4.83-2.7 4.88-10.93 4.88h-1.35c-3.82 0-8.24 2.93-12.92 3.62a68 68 0 01-9.73.5c-3.57 0-7.86-.08-13.25-.08-3.56 0-4.71-1.83-4.71-4.48h8.42a3.51 3.51 0 000-7H12.28a2.89 2.89 0 01-2.88-2.88 1.91 1.91 0 01.77-1.78h16.46a3.51 3.51 0 000-7H12.29c-3.21 0-4.84-1.83-4.84-4a6.41 6.41 0 011.17-3.78h19.06a3.5 3.5 0 100-7H9.75A3.51 3.51 0 016 42.27a3.45 3.45 0 013.75-3.48h13.11c5.61 0 7.71-3 5.71-5.52-4.43-4.74-10.84-12.62-11-18.71-.15-6.51 2.6-7.83 5.36-8.56m0-6a6.18 6.18 0 00-1.53.2c-6.69 1.77-10 6.65-9.82 14.5.08 5.09 2.99 11.18 8.52 18.09H9.74a9.52 9.52 0 00-6.23 16.9 12.52 12.52 0 00-2.07 6.84 9.64 9.64 0 003.65 7.7 7.85 7.85 0 00-1.7 5.13 8.9 8.9 0 005.3 8.13 6 6 0 00-.26 1.76c0 6.37 4.2 10.48 10.71 10.48h13.25a73.75 73.75 0 0010.6-.56 35.89 35.89 0 007.58-2.18 17.83 17.83 0 014.48-1.34h1.35c4.69 0 7.79 0 10.5-1 3.85-1.44 6-4.59 6.41-9.38.2-2.46 1.42-4.85 2.84-7.62a41.3 41.3 0 003.42-8.13 48 48 0 001.59-10.79c.1-5.13-1-8.48-3.35-10.55-2.16-1.87-4.64-1.87-9.6-1.88a46.86 46.86 0 01-6.64-.29c-1.92-.94-5.72-4-8.51-6.3l-1.58-1.28c-1.6-1.3-3.27-2.79-4.87-4.23-3.33-3-6.47-5.79-9.61-7.45a20.2 20.2 0 01-6.43-5.53 12.44 12.44 0 01-1.72-5.36 6 6 0 00-6-5.86z"})})]})},d=()=>(0,s.jsxs)("p",{children:["Let us know how these docs can be improved by",(0,s.jsx)("a",{className:"button",role:"button",tabIndex:0,onClick:a,children:"Filing a task"})]}),h=()=>(0,s.jsxs)("p",{children:["Help us make the site even better by"," ",(0,s.jsx)(i.default,{to:"https://www.surveymonkey.com/r/FYC9TCJ",children:"answering a few quick questions"}),"."]}),u=()=>(0,s.jsxs)(c,{children:[(0,s.jsx)(d,{}),(0,s.jsx)(l,{}),(0,s.jsx)(h,{})]}),p=()=>(0,s.jsxs)(c,{children:[(0,s.jsx)(l,{}),(0,s.jsx)(h,{})]}),m=()=>(0,o.fbContent)({internal:(0,s.jsx)(u,{}),external:(0,s.jsx)(p,{})})},28453(e,n,t){t.d(n,{R:()=>r,x:()=>a});var s=t(96540);let i={},o=s.createContext(i);function r(e){let n=s.useContext(o);return s.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),s.createElement(o.Provider,{value:n},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.