mirror of
https://github.com/wassname/talk.git
synced 2026-07-07 08:48:41 +08:00
Remove requirement for data.variables in withFragment
This commit is contained in:
@@ -6,27 +6,21 @@ import { getShallowChanges } from 'coral-framework/utils';
|
||||
import PropTypes from 'prop-types';
|
||||
import union from 'lodash/union';
|
||||
|
||||
// TODO: Should not depend on `props.data`
|
||||
// Currently necessary because of this https://github.com/apollographql/graphql-anywhere/issues/38
|
||||
function filter(doc, data, variables) {
|
||||
function filter(doc, data) {
|
||||
const resolver = (fieldName, root, args, context, info) => {
|
||||
return root[info.resultKey];
|
||||
};
|
||||
|
||||
return graphql(resolver, doc, data, null, variables);
|
||||
return graphql(resolver, doc, data, null, null, { includeAll: true });
|
||||
}
|
||||
|
||||
// filterProps returns only the property as defined in the fragments.
|
||||
// TODO: Should not depend on `props.data`
|
||||
function filterProps(props, fragments) {
|
||||
const filtered = {};
|
||||
Object.keys(fragments).forEach(key => {
|
||||
if (!(key in props)) {
|
||||
if (!(key in props) || props[key] === undefined) {
|
||||
return;
|
||||
}
|
||||
filtered[key] = props.data
|
||||
? filter(fragments[key], props[key], props.data.variables)
|
||||
: props[key];
|
||||
filtered[key] = filter(fragments[key], props[key]);
|
||||
});
|
||||
return filtered;
|
||||
}
|
||||
|
||||
@@ -81,8 +81,8 @@
|
||||
prettier "^1.10.2"
|
||||
|
||||
"@coralproject/graphql-anywhere-optimized@^0.1.0":
|
||||
version "0.1.5"
|
||||
resolved "https://registry.yarnpkg.com/@coralproject/graphql-anywhere-optimized/-/graphql-anywhere-optimized-0.1.5.tgz#67c862bf908ea717d9521ea76266b5bc9f109c65"
|
||||
version "0.1.6"
|
||||
resolved "https://registry.yarnpkg.com/@coralproject/graphql-anywhere-optimized/-/graphql-anywhere-optimized-0.1.6.tgz#073b33764c04788b0290788da9ebf0ed21af6437"
|
||||
dependencies:
|
||||
graphql-ast-tools "^0.2.2"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user