简体   繁体   English

express-graphql-匹配父路由的子路由

[英]express-graphql - subroutes matching parent route

So I have the following routes: /creator/item and /creator/item/price . 所以我有以下路线: /creator/item/creator/item/price Both the schemas of the two routes have a mutation called updateOne . 两条路由的两个模式都有一个名为updateOne的变异。 However, when I call the route of /creator/item/price it matches /creator/item instead. 但是,当我调用/creator/item/price的路由时,它将匹配/creator/item

Is this intended? 这是故意的吗? Is there a workaround or do I have to make a completely unique path name for it? 是否有解决方法,或者我必须为其指定一个完全唯一的路径名?

It seems like the order of definition matters. 定义的顺序似乎很重要。

Before: 之前:

// - item
const item_schema =
    require("./graphql/creator/items")
app.use(
    "/creator/item", 
    graphqlHTTP({
        schema: 
            item_schema,
        graphiql: 
            env !== "production",
        formatError
    })
)
const item_price_schema =
    require("./graphql/creator/item/prices.js")
app.use(
    // "/creator/updateOne/price", 
    "/creator/item/price", 
    graphqlHTTP({
        schema: 
            item_price_schema,
        graphiql: 
            env !== "production",
        formatError
    })
)

After: 后:

const item_price_schema =
    require("./graphql/creator/item/prices.js")
app.use(
    // "/creator/updateOne/price", 
    "/creator/item/price", 
    graphqlHTTP({
        schema: 
            item_price_schema,
        graphiql: 
            env !== "production",
        formatError
    })
)
// - item
const item_schema =
    require("./graphql/creator/items")
app.use(
    "/creator/item", 
    graphqlHTTP({
        schema: 
            item_schema,
        graphiql: 
            env !== "production",
        formatError
    })
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM