- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试创建一个 Graphql 架构,架构正在装箱,但我看不到 Id(它是 MongoDb ObjectId 类型)的过滤选项。你能告诉我我错过了什么吗?我也想按 Id 过滤,但在创建的模式上没有类似的选项。你可以在下面看到我的测试实现。
public class Startup
{
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
TypeConversion.Default.Register<string, ObjectId>(from => ObjectId.Parse(from));
TypeConversion.Default.Register<ObjectId, string>(from => from.ToString());
services.AddSingleton<IAuthorService, InMemoryAuthorService>();
services.AddGraphQL(s => SchemaBuilder.New()
.AddServices(s)
.AddType<AuthorType>()
.AddQueryType<Query>()
.BindClrType<ObjectId, IdType>()
.Create());
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UsePlayground(new PlaygroundOptions
{
QueryPath = "/api",
Path = "/playground"
});
}
app.UseRouting();
app.UseGraphQL("/api");
}
}
public class AuthorType : ObjectType<Author>
{
protected override void Configure(IObjectTypeDescriptor<Author> descriptor)
{
descriptor.Field(t => t.Id)
.Type<IdType>()
.Resolver(c => c.Parent<Author>().Id);
descriptor.Field(a => a.AuthorId).Type<StringType>();
descriptor.Field(a => a.Name).Type<StringType>();
descriptor.Field(a => a.Surname).Ignore();
}
}
public class Author
{
public ObjectId Id { get; set; }
public int AuthorId { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
}
public class Query
{
private readonly IAuthorService _authorService;
public Query(IAuthorService authorService)
{
_authorService = authorService;
}
[UsePaging]
[UseFiltering]
public IQueryable<Author> Authors() => _authorService.GetAll();
}
public interface IAuthorService
{
IQueryable<Author> GetAll();
}
public class InMemoryAuthorService : IAuthorService
{
private IList<Author> _authors;
public InMemoryAuthorService()
{
_authors = new List<Author>()
{
new Author() {Id = ObjectId.Parse("5e4442c28ae77cb23386b911"), AuthorId = 1, Name = "Name 1", Surname = "Surname 1"},
new Author() {Id = ObjectId.Parse("5e4442c28ae77cb23386b912"), AuthorId = 2, Name = "Name 2", Surname = "Surname 2"},
new Author() {Id = ObjectId.Parse("5e4442c28ae77cb23386b913"),AuthorId = 3, Name = "Name 4", Surname = "Surname 3"}
};
}
public IQueryable<Author> GetAll()
{
return _authors.AsQueryable();
}
}
最佳答案
这应该在您绑定(bind) ObjectId 类型并注册序列化时起作用
builder.BindRuntimeType<ObjectId, IdType>();
builder.AddTypeConverter<ObjectId, string>(o => o.ToString());
builder.AddTypeConverter<string,ObjectId>(o => ObjectId.Parse(o));
您可以在此处的文档中阅读有关标量的更多信息: https://chillicream.com/docs/hotchocolate/defining-a-schema/scalars/#custom-converter
关于c# - 使用 HotChocolate 按 ObjectId 类型过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64648326/
假设我在文件开头有这个定义: const ObjectId = mongoose.Types.ObjectId; 您更喜欢哪一个,为什么? // 1 new ObjectId; // 2 new O
我通过以下两种不同的方法生成了一个 ObjectId: user@ubuntu:~$ python Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24)
我编写了一个 Python 代码,用于从名为 Tweets 的 Mongo 集合中获取推文。我不想只获取对象文本并添加一个名为 Sentiment 的附加对象。 当我循环推文并将 json 对象解析为
我是 Node.js 和 mongodb 的新手。 在我的 Node.js 应用程序中,我使用的是 mongodb,对于 mongodb 操作,我使用的是 mongoose。 在 package.js
使用 parse.com 和 JavaScript SDK。 这就是我想要实现的目标。 页面上将用户( friend )列表返回给用户,然后他们可以单击其中一个用户,页面将更新以列出所有该用户的项目(
我有一个像这样的 objectId:["56153e4c2040efa61b4e267f","56033932efefe0d8657bbd9e"]为了在我的模型中保存该信息,我使用: items: [
我有一个标签模式: const TagSchema = new Schema({ label: {type: String, unique: true, minlength: 2}, upda
在online API他们指的是 Mongo::ObjectID。 我有 require 'mongo' 但 ruby 仍然找不到它。例如,我需要通过它的 Id 找到一个对象,我正在做: mong
作为管道的最后阶段,我有一个像这样的 $project : { ... anId : new ObjectId() } 但是 mongo 为每个文档生成相同的 Id。我希望它为每个投影文档生成
我需要在这样的数组中找到 mongoose objectID 的索引: [ { _id: 58676b0a27b3782b92066ab6, score: 0 }, { _id: 58676aca
我们可以从客户端生成 ObjectId 并在插入时使用它。我确实希望它在插入过程之外进行处理。我需要将其配置为我的默认 _id 生成过程,以便当我调用 insert 时,insert 方法应该创建自定
这是代码。跟随者和追随者无法工作。换句话说,我无法将像 {"user1", objectId1} 这样的对象推送到这两个数组。是否允许有一个字段同时包含对象 ID 和字符串名称?感谢您的帮助。 The
为什么 Meteor.js 使用它自己的 IDsp 算法> 为什么不使用 MongoDB ObjectId()? 最佳答案 如果你选择使用 Meteor,它对对象 ID 使用相同的方法: Meteor
Mongoose 菜鸟问题:我有两个 Mongoose ObjectId 对象列表,我将它们合并为一个。有些 ObjectId 是重复的,我不想将它们保存到我的数据库中。是否有 Mongoose 工具
以下代码从供应商集合中的员工数组中提取员工 await new VendorManager() .update( { emplo
我有一个简单的模型对象: class UserRating include MongoMapper::EmbeddedDocument key :idea_id, ObjectId key
谁能告诉我使用 #[objectId] 或 [id=objectId] 引用元素有什么区别? 最佳答案 第一个非常快,因为 jQuery 内部使用 getElementById当它识别出模式时(使用正
我的架构是: var schema = new Schema({ players: { type: [Schema.Types.ObjectId]}); 我正在使用 promi
这似乎是这样定义我的架构: var PossessionSchema = new mongoose.Schema({ thing: {type: mongoose.Schema.Types.Obj
我想要解决的是:使用建议的方法(mapReduce)保留 $in 中的 Id 数组的顺序: Does MongoDB's $in clause guarantee order 我已经完成了我的作业,发
我是一名优秀的程序员,十分优秀!