Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何解决GraphQL中的命名冲突?_Javascript_Graphql_Graphql Tools - Fatal编程技术网

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

Javascript 如何解决GraphQL中的命名冲突?,javascript,graphql,graphql-tools,Javascript,Graphql,Graphql Tools,上面的例子运行得很好,但我想使用一个突变名称来增加长度,而不是增加鱼的长度和绳子的长度 我试着用斜杠来命名鱼/增加长度和绳子/增加长度,但没用。(只有/[[u A-Za-z][[u 0-9A-Za-z]*/可用。) GraphQl支持名称空间的任何解决方案吗?GraphQl不支持类似名称空间的东西我一直在玩弄有关名称空间的一些想法。如果您的类型定义如下所示: import { makeExecutableSchema } from 'graphql-tools'; const fish = {

上面的例子运行得很好,但我想使用一个突变名称来增加长度,而不是增加鱼的长度和绳子的长度

我试着用斜杠来命名鱼/增加长度和绳子/增加长度,但没用。(只有/[[u A-Za-z][[u 0-9A-Za-z]*/可用。)


GraphQl支持名称空间的任何解决方案吗?

GraphQl不支持类似名称空间的东西

我一直在玩弄有关名称空间的一些想法。如果您的类型定义如下所示:

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 });
type Mutation {
    increase_length: IncreaseLengthMutation!
}

type IncreaseLengthMutation {
    fish: Fish!
    rope: Rope!
}
您的解析器如下所示:

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 });
type Mutation {
    increase_length: IncreaseLengthMutation!
}

type IncreaseLengthMutation {
    fish: Fish!
    rope: Rope!
}

最大的缺点是不可靠的变异解析器返回空数组。但是,它必须存在,才能级联到其他突变。

Yeah~!我过去常常把这个想法应用到查询中。我得考虑一下。谢谢分享你的想法!