Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
528 views
in Technique[技术] by (71.8m points)

GraphQL stitchSchemas type merging works with argsFromKeys but not with args

What's the difference between args and keys/argsFromKeys when merging types?

Is there any reason args would not work?

My understanding from the GraphQL Tools docs is it's simply single result queries vs arrays... getUserByID(id: String) vs getUsersByIDs(ids: [String]) but this alone doesn't explain my experience. After many hours I've found one works for me but not the other.

Works:

merge: {
    Product: {
        fieldName: 'Product',
        selectionSet: '{id}',

        key: (record) => {
            return record.id;
        },    

        argsFromKeys: (keys) => {
            var arg = { filter: { id_in: keys }};
            console.log(arg); // { where: { id_in: ["475e006f-b9cg-4f40-8712-271ceb46d14b"]}

            //expected query: Product(where:{id_in: ["475e006f-b9cg-4f40-8712-271ceb46d14b"]})
            return arg;
        }
    }
}

Does not work (resolves to undefined):

merge: {
    Product: {
        fieldName: 'Product',
        selectionSet: '{id}',
        args: (originalObject) => {
            var arg = { id: originalObject.id };
            console.log(arg); // { id: "475e006f-b9cg-4f40-8712-271ceb46d14b" }

            // expected query: Product(id: "475e006f-b9cg-4f40-8712-271ceb46d14b")
            return arg;
        }
    }
}

Does not work either - even using the same query as argsFromKeys:

merge: {
        Product: {
            fieldName: 'Product',
            selectionSet: '{id}',
            args: (originalObject) => {
                var arg = { where: { id_in: [originalObject.id] };
                    console.log(arg); // { where: { id_in: ["475e006f-b9cg-4f40-8712-271ceb46d14b"]}

                    //expected query: Product(where:{id_in: ["475e006f-b9cg-4f40-8712-271ceb46d14b"]})
                    return arg;
                }

            }
        }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...