【发布时间】:2021-01-16 07:24:05
【问题描述】:
在热巧克力研讨会之后和第四步之后,运行查询时
query GetSpecificSpeakerById {
a: speakerById(id: 1) {
name
}
b: speakerById(id: 1) {
name
}
}
我收到以下错误。
The ID `1` has an invalid format.
此外,所有以 ID 作为参数的查询都会引发相同的错误,也许这可能是一个提示,对于我这个刚刚运行研讨会的人来说,检查什么仍然不清楚。
基于类似问题Error "The ID `1` has an invalid format" when querying HotChocolate 中的(不接受)答案,我检查了 Relay,它的配置看起来不错。
DI
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton(CreateAutomapper());
services.AddPooledDbContextFactory<ApplicationDbContext>(options =>
options.UseSqlite(CONNECTION_STRING).UseLoggerFactory(ApplicationDbContext.DbContextLoggerFactory));
services
.AddGraphQLServer()
.AddQueryType(d => d.Name(Consts.QUERY))
.AddTypeExtension<SpeakerQueries>()
.AddTypeExtension<SessionQueries>()
.AddTypeExtension<TrackQueries>()
.AddMutationType(d => d.Name(Consts.MUTATION))
.AddTypeExtension<SpeakerMutations>()
.AddTypeExtension<SessionMutations>()
.AddTypeExtension<TrackMutations>()
.AddType<AttendeeType>()
.AddType<SessionType>()
.AddType<SpeakerType>()
.AddType<TrackType>()
.EnableRelaySupport()
.AddDataLoader<SpeakerByIdDataLoader>()
.AddDataLoader<SessionByIdDataLoader>();
}
扬声器类型
public class SpeakerType : ObjectType<Speaker>
{
protected override void Configure(IObjectTypeDescriptor<Speaker> descriptor)
{
descriptor
.ImplementsNode()
.IdField(p => p.Id)
.ResolveNode(WithDataLoader);
}
// implementation
}
并查询自己
[ExtendObjectType(Name = Consts.QUERY)]
public class SpeakerQueries
{
public Task<Speaker> GetSpeakerByIdAsync(
[ID(nameof(Speaker))] int id,
SpeakerByIdDataLoader dataLoader,
CancellationToken cancellationToken) => dataLoader.LoadAsync(id, cancellationToken);
}
但没有一点运气。还有什么,我可以检查什么?完整的项目是available on my GitHub。
【问题讨论】:
-
什么乱七八糟...graphql 服务器通常响应更有意义的错误...检查 graphiql/docs - 预期的 arg 类型,也许它应该是一个字符串
标签: graphql hotchocolate