我不明白跟踪查询的工作方式。
这里有一个我的应用程序:
GRAPHQL
type Admin implements Node {
id: ID!
program(slug: String!): Program
}
type Program implements Node {
id: ID!
slug: String!
assessmentLink: String!
subjectSubscription: Boolean!
}
input ProgramSetSubjectSubscriptionInput {
programID: ID!
subjectSubscription: Boolean!
clientMutationId: String!
}
type ProgramSetSubjectSubscriptionPayload {
program: Program
clientMutationId: String!
}
type Mutations {
programSetSubjectSubscription(input: ProgramSetSubjectSubscriptionInput!): ProgramSetSubjectSubscriptionPayload
}
服务器端突变
import {
GraphQLBoolean,
GraphQLFloat,
GraphQLID,
GraphQLInt,
GraphQLList,
GraphQLNonNull,
GraphQLObjectType,
GraphQLInputObjectType,
GraphQLSchema,
GraphQLString
} from 'graphql';
import {
fromGlobalId,
mutationWithClientMutationId,
cursorForObjectInConnection,
offsetToCursor
} from 'graphql-relay';
import _ from 'lodash';
import db from '../../db';
import Program from '../types/Program';
import Admin, { ProgramEdge } from '../types/Admin';
export default mutationWithClientMutationId({
name : 'ProgramSetSubjectSubscription',
inputFields : {
programID : {
type : new GraphQLNonNull( GraphQLID )
},
subjectSubscription : {
type : new GraphQLNonNull( GraphQLBoolean )
}
},
async mutateAndGetPayload({ programID, subjectSubscription }) {
const Program = db.model('Program');
const localProgramId = fromGlobalId( programID ).id;
const program = await Program.findById( localProgramId ).exec();
program.subjectSubscription = subjectSubscription;
await program.save();
return {
localProgramId : program.id
};
},
outputFields : {
program : {
type : Program,
async resolve({ localProgramId }) {
const Program = db.model('Program');
return await Program.findById( localProgramId ).exec();
}
}
}
});
客户端突变
import Relay from 'react-relay';
export default class ProgramSetSubjectSubscription extends Relay.Mutation {
static fragments = {
program() {
return Relay.QL`
fragment on Program {
id
}
`
}
};
getMutation() {
return Relay.QL`mutation{programSetSubjectSubscription}`;
}
getFatQuery() {
return Relay.QL`
fragment on ProgramSetSubjectSubscriptionPayload {
program {
subjectSubscription
}
}
`;
}
getConfigs() {
return [
{
type: 'FIELDS_CHANGE',
fieldsIDs : {
program : this.props.program.id
}
}
];
}
getVariables() {
return {
programID : this.props.program.id,
subjectSubscription : this.props.subjectSubscription
};
}
}
现在我有一个名为Container
的{{1}} ProgramCard
,如下所示:
fragment
fragment on Program {
name,
assessmentLink,
subjectSubscription,
${ProgramAutoInviteToggle.getFragment('program')}
${ProgramSubjectRegistrationLink.getFragment('program')}
}
会调用Mutation
,并应切换此ProgramAutoInviteToggle
Program
字段的值。
在subjectSubscription
呈现方法中,我想要显示或不显示ProgramCard
,具体取决于ProgramSubjectRegistrationLink
值。
问题在于客户端实际发生的突变如下:
subjectSubscription
没有query:
mutation ProgramSetSubjectSubscription($input_0:ProgramSetSubjectSubscriptionInput!){programSetSubjectSubscription(input:$input_0){clientMutationId}}
variables:
{
"input_0": {
"programID": "UHJvZ3JhbTo1NjM2OTY1MzFiZGM3MzI1MmFlYTk4MWE=",
"subjectSubscription": false,
"clientMutationId": "0"
}
}
字段的痕迹。为什么?
非常感谢你帮我解决这个问题。我真的无法理解!
答案 0 :(得分:0)
是否可以使用fieldIDs
的正确拼写?
getConfigs() {
return [
{
type: 'FIELDS_CHANGE',
fieldIDs: { // Instead of `fieldsIDs`
program: this.props.program.id
}
}
];
}