简体   繁体   中英

express-graphql - subroutes matching parent route

So I have the following routes: /creator/item and /creator/item/price . Both the schemas of the two routes have a mutation called updateOne . However, when I call the route of /creator/item/price it matches /creator/item instead.

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
    })
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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