@@ -1160,6 +1160,33 @@ <h3 id="32-code-classlanguage-textigraphqlbuildervalidateservicescode-added-to-v
11601160 < span class ="token class-name "> < span class ="token keyword "> var</ span > </ span > service < span class ="token operator "> =</ span > context< span class ="token punctuation "> .</ span > RequestServices< span class ="token operator "> !</ span > < span class ="token punctuation "> .</ span > < span class ="token generic-method "> < span class ="token function "> GetRequiredService</ span > < span class ="token generic class-name "> < span class ="token punctuation "> <</ span > IMyService< span class ="token punctuation "> > </ span > </ span > </ span > < span class ="token punctuation "> (</ span > < span class ="token punctuation "> )</ span > < span class ="token punctuation "> ;</ span >
11611161 < span class ="token keyword "> return</ span > service< span class ="token punctuation "> .</ span > < span class ="token function "> GetMyValue</ span > < span class ="token punctuation "> (</ span > < span class ="token punctuation "> )</ span > < span class ="token punctuation "> ;</ span >
11621162 < span class ="token punctuation "> }</ span > < span class ="token punctuation "> )</ span > < span class ="token punctuation "> ;</ span > </ code > </ pre > </ div >
1163+ < h3 id ="33-added-capability-to-reference-object-graph-types-from-their-implementing-interfaces-850 " style ="position:relative; "> < a href ="#33-added-capability-to-reference-object-graph-types-from-their-implementing-interfaces-850 " aria-label ="33 added capability to reference object graph types from their implementing interfaces 850 permalink " class ="anchor before "> < svg aria-hidden ="true " focusable ="false " height ="16 " version ="1.1 " viewBox ="0 0 16 16 " width ="16 "> < path fill-rule ="evenodd " d ="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z "> </ path > </ svg > </ a > 33. Added capability to reference object graph types from their implementing interfaces (8.5.0+)</ h3 >
1164+ < p > GraphQL.NET allows developers to configure object graph types to reference interfaces that they
1165+ implement via the < code class ="language-text "> Interface<T> ()</ code > or < code class ="language-text "> AddResolvedInterface(IInterfaceGraphType type)</ code > .
1166+ Alternatively, you may reference the object graph type from the interface by using
1167+ < code class ="language-text "> AddPossibleType(IObjectGraphType type)</ code > . However, this requires a concrete reference to the
1168+ instantiated class rather than just the < code class ="language-text "> Type</ code > to be resolved during schema initialization.</ p >
1169+ < p > In version 8.5.0+, you may use < code class ="language-text "> Type<TObjectType> ()</ code > or < code class ="language-text "> Type(Type objectType)</ code > to reference
1170+ the object type from the interface type. This matches the same methods already available on
1171+ < code class ="language-text "> UnionGraphType</ code > , unifying the API between unions and interfaces. The new methods will be
1172+ added to < code class ="language-text "> IAbstractGraphType</ code > in version 9, which is implemented by both < code class ="language-text "> UnionGraphType</ code >
1173+ and < code class ="language-text "> IInterfaceGraphType</ code > . For example:</ p >
1174+ < div class ="gatsby-highlight " data-language ="csharp "> < pre class ="language-csharp "> < code class ="language-csharp "> < span class ="token keyword "> public</ span > < span class ="token keyword "> class</ span > < span class ="token class-name "> MyInterfaceGraphType</ span > < span class ="token punctuation "> :</ span > < span class ="token type-list "> < span class ="token class-name "> InterfaceGraphType</ span > </ span >
1175+ < span class ="token punctuation "> {</ span >
1176+ < span class ="token keyword "> public</ span > < span class ="token function "> MyInterfaceGraphType</ span > < span class ="token punctuation "> (</ span > < span class ="token punctuation "> )</ span >
1177+ < span class ="token punctuation "> {</ span >
1178+ < span class ="token generic-method "> < span class ="token function "> Type</ span > < span class ="token generic class-name "> < span class ="token punctuation "> <</ span > MyObjectGraphType< span class ="token punctuation "> > </ span > </ span > </ span > < span class ="token punctuation "> (</ span > < span class ="token punctuation "> )</ span > < span class ="token punctuation "> ;</ span >
1179+ < span class ="token generic-method "> < span class ="token function "> Field</ span > < span class ="token generic class-name "> < span class ="token punctuation "> <</ span > < span class ="token keyword "> string</ span > < span class ="token punctuation "> > </ span > </ span > </ span > < span class ="token punctuation "> (</ span > < span class ="token string "> "Name"</ span > < span class ="token punctuation "> )</ span > < span class ="token punctuation "> ;</ span >
1180+ < span class ="token punctuation "> }</ span >
1181+ < span class ="token punctuation "> }</ span > </ code > </ pre > </ div >
1182+ < p > For type-first users, a new attribute < code class ="language-text "> [PossibleType(Type objectType)]</ code > has been added which
1183+ can be marked on interface CLR types to reference an object CLR or graph type that the interface
1184+ type implements. For instance:</ p >
1185+ < div class ="gatsby-highlight " data-language ="csharp "> < pre class ="language-csharp "> < code class ="language-csharp "> < span class ="token punctuation "> [</ span > < span class ="token attribute "> < span class ="token class-name "> PossibleType</ span > < span class ="token attribute-arguments "> < span class ="token punctuation "> (</ span > < span class ="token keyword "> typeof</ span > < span class ="token punctuation "> (</ span > < span class ="token type-expression class-name "> MyObject</ span > < span class ="token punctuation "> )</ span > < span class ="token punctuation "> )</ span > </ span > </ span > < span class ="token punctuation "> ]</ span >
1186+ < span class ="token keyword "> public</ span > < span class ="token keyword "> interface</ span > < span class ="token class-name "> IMyInterface</ span >
1187+ < span class ="token punctuation "> {</ span >
1188+ < span class ="token keyword "> public</ span > < span class ="token return-type class-name "> < span class ="token keyword "> string</ span > </ span > Name < span class ="token punctuation "> {</ span > < span class ="token keyword "> get</ span > < span class ="token punctuation "> ;</ span > < span class ="token keyword "> set</ span > < span class ="token punctuation "> ;</ span > < span class ="token punctuation "> }</ span >
1189+ < span class ="token punctuation "> }</ span > </ code > </ pre > </ div >
11631190< h2 id ="breaking-changes " style ="position:relative; "> < a href ="#breaking-changes " aria-label ="breaking changes permalink " class ="anchor before "> < svg aria-hidden ="true " focusable ="false " height ="16 " version ="1.1 " viewBox ="0 0 16 16 " width ="16 "> < path fill-rule ="evenodd " d ="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z "> </ path > </ svg > </ a > Breaking Changes</ h2 >
11641191< h3 id ="1-query-type-is-required " style ="position:relative; "> < a href ="#1-query-type-is-required " aria-label ="1 query type is required permalink " class ="anchor before "> < svg aria-hidden ="true " focusable ="false " height ="16 " version ="1.1 " viewBox ="0 0 16 16 " width ="16 "> < path fill-rule ="evenodd " d ="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z "> </ path > </ svg > </ a > 1. Query type is required</ h3 >
11651192< p > Pursuant to the GraphQL specification, a query type is required for any schema.
0 commit comments