Javascript 字符串不能表示值GraphQL
我正在构建一个GraphQLAPI,在我的一个端点中,我遇到了这个问题,它表示“消息”:“字符串不能表示值:[\“Vitoria\”,“Serra\”,“Cariacica\”,“Vila Velha\”] 我已尝试更改类型:GraphQListJavascript 字符串不能表示值GraphQL,javascript,graphql,Javascript,Graphql,我正在构建一个GraphQLAPI,在我的一个端点中,我遇到了这个问题,它表示“消息”:“字符串不能表示值:[\“Vitoria\”,“Serra\”,“Cariacica\”,“Vila Velha\”] 我已尝试更改类型:GraphQList const alfa_regions = [ {ES_capital: ['Vitoria', 'Serra', 'Cariacica', 'Vila Velha']}, {ES_Interior: ['Piuma', 'Sao Ga
const alfa_regions = [
{ES_capital: ['Vitoria', 'Serra', 'Cariacica', 'Vila Velha']},
{ES_Interior: ['Piuma', 'Sao Gabriel']},
{MG_Capital: ['Contagem']},
{MG_Interior: ['Juiz de fora', 'Governador Valadares', 'Teofilo Otoni', 'Monte Claros']},
]
const {
GraphQLObjectType,
GraphQLSchema,
GraphQLString,
GraphQLFloat,
GraphQLList
} = graphql
const AlfaRegionType = new GraphQLObjectType({
name: 'AlfaRegion',
fields: () => ({
id: {type: GraphQLString},
region_id: {type: GraphQLString},
ES_capital: {type: GraphQLString},
})
})
const RootQuery = new GraphQLObjectType({
name: 'RootQueryType',
fields: {
regions: {
type: AlfaRegionType,
args: {id: {type: GraphQLString}},
resolve(parent, args){
return _.find(alfa_regions, {})
}
}
}
})
如果字段返回字符串数组,而不仅仅是单个字符串,则应使用
graphqlist
作为类型,如图所示:
或者使用SDL
[String]
[String!]
[String!]!
如果数组不包含任何空值,那么最好这样做
type: new GraphQLList(new GraphQLNonNull(GraphQLString))
或者使用SDL
[String]
[String!]
[String!]!
如果数组不包含任何空值,并且字段本身永远不会为空,则执行以下操作:
type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(GraphQLString)))
或者使用SDL
[String]
[String!]
[String!]!