在进行常规的graphQL查询时,我可以轻松获得嵌套对象或计算。 但在订阅内容时:
import matplotlib.pyplot as plt
import numpy as np
data = [1.4, 1.4, 1.4, 1.5, 1.5, 1.6, 1.7, 1.7, 1.7, 1.9, 1.9, 1.9, 1.9, 2.0,
2.0, 2.0, 2.1, 2.1, 2.1, 2.1, 2.2, 2.2, 2.3, 2.3, 2.3, 2.4, 2.5, 2.6,
2.7, 2.7, 2.8, 2.8, 2.8, 2.9, 2.9, 3.1, 3.1, 3.2, 3.2, 3.5, 3.6, 3.8]
fig, ax = plt.subplots(nrows=1, ncols=1)
bins=[1.4,1.5,1.6,1.7,1.9,2.0,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3.1,3.2,3.5,3.6,3.8]
ax.hist(data, bins=bins, facecolor='blue', edgecolor='gray', rwidth=1, align='mid')
ax.set_xticks(bins)
ax.set_ylabel('Frequency')
ax.set_xlabel('DRA Sizes(mm)')
ax.set_title('Frequencies of DRA Sizes in Males (mm)')
plt.show()
我添加subscription {
Event(filter: {
mutation_in: [CREATED]
}) {
node {
title
description
start
end
seats
bookings
owner {
email
}
}
}
}
或bookings
后会立即中断。我在服务器上看不到任何错误消息。 QraphiQL仅显示owner { ... }
作为响应。
[object Object]
type Event {
id: ID!
title: String!
description: String!
owner: User!
seats: Int
bookings: Int
start: DateTime!
end: DateTime!
tickets: [EventTicket!]!
}
type Mutation {
createEvent(event: EventInput!): Event
}
input EventInput {
title: String!
description: String!
seats: Int
start: DateTime!
end: DateTime!
}
type Subscription {
Event(filter: EventSubscriptionFilter): EventSubscriptionPayload
}
input EventSubscriptionFilter {
mutation_in: [_ModelMutationType!]
}
type EventSubscriptionPayload {
mutation: _ModelMutationType!
node: Event
}
enum _ModelMutationType {
CREATED
UPDATED
DELETED
}
有关如何处理此问题的任何想法(和/或如何获取正确的错误消息来调试^^)。
答案 0 :(得分:1)
搜索后确定I found the solution/hack here。
SubscriptionServer.create(
{
execute, subscribe, schema,
onOperation: (message, params, webSocket) => {
return { ...params, context: {mongo} }
},
},
{ server, path: '/subscriptions' },
);
感谢nharraud。