javascript - 如何解决 GraphQL 中的命名冲突?

标签 javascript graphql graphql-tools

import { makeExecutableSchema } from 'graphql-tools';

const fish = { length:50 },
      rope = { length:100 };

const typeDefs = `
    type Query {
        rope: Rope!
        fish: Fish!
    }

    type Mutation {
        increase_fish_length: Fish!
        increase_rope_length: Rope!
    }

    type Rope {
        length: Int!
    }

    type Fish {
        length: Int!
    }
`;

const resolvers = {
    Mutation: {
        increase_fish_length: (root, args, context) => {
            fish.length++;
            return fish;
        },
        increase_rope_length: (root, args, context) => {
            rope.length++;
            return rope;
        }
    }
};

export const schema = makeExecutableSchema({ typeDefs, resolvers });

以上示例运行良好,但我想使用突变名称 increase_length 而不是 increase_fish_lengthincrease_rope_length

我尝试使用斜杠命名突变 Fish/increase_lengthRope/increase_length,但没有成功。 (只有/[_A-Za-z][_0-9A-Za-z]*/可用。)

GraphQl 是否支持命名空间的任何解决方案?

最佳答案

Graphql 不支持类似命名空间的东西

关于javascript - 如何解决 GraphQL 中的命名冲突?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51909282/

相关文章:

graphql - 枚举 GraphQL 查询中的所有字段

javascript - 如何迭代对象值并在所有对象值都被填充时有条件地触发事件?

javascript - parsley js 验证 - 优先考虑验证约束和自定义错误消息

使用graphql在spring boot中进行身份验证

ruby-on-rails - 无法写入未知属性 `client_mutation_id`

node.js - 来自 GraphQLObjectType 模式的 graphql mergeSchemas

javascript - 如何在 graphql-tool 中传递查询参数?

javascript - 在 HTML5 上取消滚动

javascript - 在 chrome 扩展中创建 HTML 对话框弹出窗口

graphql - GraphQL#execute 是否在同一线程上运行所有 DataFetcher?异步行为是否委托(delegate)给 DataFetcher 实现?