/// <summary> /// Method parameters with the following type are ignored in the schema and will have their value injected: /// <list type="bullet"> /// <item><see cref="IResolveFieldContext"/></item> /// </list> /// </summary> /// <param name="method">Graph endpoint implementation</param> /// <remarks>The method's type must be registered in the <see cref="IServiceCollection"/>.</remarks> /// <returns>The added <see cref="FieldType"/>.</returns> public FieldType AddQuery(MethodMember method) { var handler = !method.Static ? this._ServiceProvider.GetRequiredService(method.Type) : null; var resolver = new MethodFieldResolver(method, handler); return(this.Query.AddField(method.ToFieldType(resolver))); }
/// <summary> /// Adds a subquery to an existing parent type that returns a single item mapped to the parent type by a key property.<br /> /// Method parameters with the following types are ignored in the schema and will have their value injected: /// <list type="bullet"> /// <item><see cref="IResolveFieldContext"/></item> /// <item>PARENT</item> /// <item>IEnumerable<KEY></item> /// </list> /// </summary> /// <remarks>The method's type must be registered in the <see cref="IServiceCollection"/>.</remarks> /// <typeparam name="PARENT">The parent type to add the endpount to</typeparam> /// <typeparam name="CHILD">The mapped child type to be returned</typeparam> /// <typeparam name="KEY">The type of the key mapping between the parent and child types.</typeparam> /// <param name="method">Graph endpoint implementation</param> /// <param name="getParentKey">Gets the key value from the parent instance</param> /// <param name="getChildKey">Gets the key value from the child instance</param> /// <returns>The added <see cref="FieldType"/>.</returns> public FieldType AddSubqueryBatch <PARENT, CHILD, KEY>(MethodMember method, Func <PARENT, KEY> getParentKey, Func <CHILD, KEY> getChildKey) where PARENT : class { var handler = this._ServiceProvider.GetRequiredService(method.Type); var resolver = new BatchLoaderFieldResolver <PARENT, CHILD, KEY>(method, handler, this._DataLoader, getParentKey, getChildKey); return(this.Query.AddField(method.ToFieldType(resolver))); }
/// <summary> /// Adds a subquery to an existing parent type that returns a single item.<br /> /// Method parameters with the following types are ignored in the schema and will have their value injected: /// <list type="bullet"> /// <item><see cref="IResolveFieldContext"/></item> /// <item>T</item> /// </list> /// </summary> /// <remarks>The method's type must be registered in the <see cref="IServiceCollection"/>.</remarks> /// <param name="method">Graph endpoint implementation</param> /// <returns>The added <see cref="FieldType"/>.</returns> public FieldType AddSubquery <T>(MethodMember method) where T : class { var handler = this._ServiceProvider.GetRequiredService(method.Type); var resolver = new ItemLoaderFieldResolver <T>(method, handler, this._DataLoader); return(this.Query.AddField(method.ToFieldType(resolver))); }
/// <summary> /// Adds a subquery to an existing parent type that returns a collection of items mapped to the parent type by a key property. /// Method parameters with the following types are ignored in the schema and will have their value injected: /// <list type="bullet"> /// <item><see cref="IResolveFieldContext"/></item> /// <item>PARENT</item> /// <item>IEnumerable<KEY></item> /// </list> /// </summary> /// <remarks>The method's type must be registered in the <see cref="IServiceCollection"/>.</remarks> /// <typeparam name="PARENT">The parent type to add the endpount to</typeparam> /// <typeparam name="CHILD">The mapped child type to be returned</typeparam> /// <typeparam name="KEY">The type of the key mapping between the parent and child types.</typeparam> /// <param name="method">Graph endpoint implementation</param> /// <param name="getParentKey">Gets the key value from the parent instance</param> /// <param name="getChildKey">Gets the key value from the child instance</param> /// <returns>The added <see cref="FieldType"/>.</returns> public FieldType AddSubqueryCollection <PARENT, CHILD, KEY>(MethodMember method, Func <PARENT, KEY> getParentKey, Func <CHILD, KEY> getChildKey) where PARENT : class { if (!method.Return.Type.Implements <IEnumerable <CHILD> >()) { throw new ArgumentException($"{nameof(AddSubquery)}: Expected method [{method.Name}] to have a return type of [{TypeOf<IEnumerable<CHILD>>.Name}] instead of [{method.Return.Type.Name}]."); } var handler = this._ServiceProvider.GetRequiredService(method.Type); var resolver = new CollectionBatchLoaderFieldResolver <PARENT, CHILD, KEY>(method, handler, this._DataLoader, getParentKey, getChildKey); return(this.Query.AddField(method.ToFieldType(resolver))); }
/// <summary> /// Adds a subquery to an existing parent type that returns a collection of items mapped to the parent type by a key property. /// Method parameters with the following types are ignored in the schema and will have their value injected: /// <list type="bullet"> /// <item><see cref="IResolveFieldContext"/></item> /// <item>PARENT</item> /// <item>IEnumerable<KEY></item> /// </list> /// </summary> /// <remarks>The method's type must be registered in the <see cref="IServiceCollection"/>.</remarks> /// <param name="method">Graph endpoint implementation</param> /// <param name="parentPropertyKey">Parent property containing the key value</param> /// <param name="childPropertyKey">Child property containing the key value</param> /// <returns>The added <see cref="FieldType"/>.</returns> public FieldType AddSubqueryCollection(MethodMember method, PropertyMember parentPropertyKey, PropertyMember childPropertyKey) { var handler = this._ServiceProvider.GetRequiredService(method.Type); if (parentPropertyKey.PropertyType != childPropertyKey.PropertyType) { throw new ArgumentException($"{nameof(AddSubquery)}: Expected properties [{parentPropertyKey.Name}] and [{childPropertyKey.Name}] to have the same type; instead of [{parentPropertyKey.PropertyType.Name}] and [{childPropertyKey.PropertyType.Name}]."); } var resolverType = typeof(CollectionBatchLoaderFieldResolver <, ,>).MakeGenericType(parentPropertyKey.Type, childPropertyKey.Type, childPropertyKey.PropertyType); var resolver = (IFieldResolver)resolverType.GetTypeMember().Create(method, handler, this._DataLoader, parentPropertyKey, childPropertyKey); return(this.Query.AddField(method.ToFieldType(resolver))); }