【问题标题】:express-graphql - subroutes matching parent routeexpress-graphql - 匹配父路由的子路由
【发布时间】:2019-07-20 23:20:22
【问题描述】:

所以我有以下路线:/creator/item/creator/item/price。两条路线的两种模式都有一个名为updateOne 的突变。但是,当我调用/creator/item/price 的路线时,它会匹配/creator/item

这是故意的吗?是否有解决方法或者我必须为其创建一个完全唯一的路径名?

【问题讨论】:

    标签: javascript node.js graphql graphql-js express-graphql


    【解决方案1】:

    似乎定义的顺序很重要。

    之前:

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

    之后:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-17
      • 2021-12-09
      • 2018-03-31
      • 2021-08-13
      • 1970-01-01
      • 2015-09-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多