From 95a7a1ca47a1f4e103cd9522b3f1478c92a9d5da Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Fri, 12 May 2017 20:15:04 +0700 Subject: [PATCH] Rename registry --- .../coral-embed-stream/src/graphql/index.js | 6 +-- client/coral-framework/helpers/plugins.js | 2 +- client/coral-framework/hocs/withMutation.js | 6 +-- client/coral-framework/hocs/withQuery.js | 4 +- .../{registry.js => graphqlRegistry.js} | 44 +++++++++---------- 5 files changed, 31 insertions(+), 31 deletions(-) rename client/coral-framework/services/{registry.js => graphqlRegistry.js} (76%) diff --git a/client/coral-embed-stream/src/graphql/index.js b/client/coral-embed-stream/src/graphql/index.js index a123de7e7..daa8389b3 100644 --- a/client/coral-embed-stream/src/graphql/index.js +++ b/client/coral-embed-stream/src/graphql/index.js @@ -1,8 +1,8 @@ import {gql} from 'react-apollo'; -import {registerConfig} from 'coral-framework/services/registry'; +import {add} from 'coral-framework/services/graphqlRegistry'; import update from 'immutability-helper'; -const config = { +const extension = { fragments: { EditCommentResponse: gql` fragment CoralEmbedStream_EditCommentResponse on EditCommentResponse { @@ -267,4 +267,4 @@ const config = { }, }; -registerConfig(config); +add(extension); diff --git a/client/coral-framework/helpers/plugins.js b/client/coral-framework/helpers/plugins.js index e55715e4b..bde7f9d68 100644 --- a/client/coral-framework/helpers/plugins.js +++ b/client/coral-framework/helpers/plugins.js @@ -82,7 +82,7 @@ export function getSlotsFragments(slots) { }; } -export function getGraphQLConfigs() { +export function getGraphQLExtensions() { return plugins .map(o => pick(o.module, ['mutations', 'queries', 'fragments'])) .filter(o => o); diff --git a/client/coral-framework/hocs/withMutation.js b/client/coral-framework/hocs/withMutation.js index 59a4fb627..c08a53614 100644 --- a/client/coral-framework/hocs/withMutation.js +++ b/client/coral-framework/hocs/withMutation.js @@ -4,13 +4,13 @@ import merge from 'lodash/merge'; import uniq from 'lodash/uniq'; import flatten from 'lodash/flatten'; import isEmpty from 'lodash/isEmpty'; -import {getMutationOptions, resolveFragments} from 'coral-framework/services/registry'; +import {getMutationOptions, resolveFragments} from 'coral-framework/services/graphqlRegistry'; import {store} from 'coral-framework/services/store'; import {getDefinitionName} from '../utils'; /** * Exports a HOC with the same signature as `graphql`, that will - * apply mutation options registered in the registry. + * apply mutation options registered in the graphRegistry. */ export default (document, config) => WrappedComponent => { config = { @@ -80,7 +80,7 @@ export default (document, config) => WrappedComponent => { return config.props({...data, mutate}); }; - // Lazily resolve fragments from registry to support circular dependencies. + // Lazily resolve fragments from graphRegistry to support circular dependencies. let memoized = null; const getWrapped = () => { if (!memoized) { diff --git a/client/coral-framework/hocs/withQuery.js b/client/coral-framework/hocs/withQuery.js index 6a5fa7c14..a29d25241 100644 --- a/client/coral-framework/hocs/withQuery.js +++ b/client/coral-framework/hocs/withQuery.js @@ -1,11 +1,11 @@ import * as React from 'react'; import {graphql} from 'react-apollo'; -import {getQueryOptions, resolveFragments} from 'coral-framework/services/registry'; +import {getQueryOptions, resolveFragments} from 'coral-framework/services/graphqlRegistry'; import {getDefinitionName, separateDataAndRoot} from '../utils'; /** * Exports a HOC with the same signature as `graphql`, that will - * apply query options registered in the registry. + * apply query options registered in the graphRegistry. */ export default (document, config) => WrappedComponent => { config = { diff --git a/client/coral-framework/services/registry.js b/client/coral-framework/services/graphqlRegistry.js similarity index 76% rename from client/coral-framework/services/registry.js rename to client/coral-framework/services/graphqlRegistry.js index 8fe934730..78d27d038 100644 --- a/client/coral-framework/services/registry.js +++ b/client/coral-framework/services/graphqlRegistry.js @@ -1,5 +1,5 @@ import {getDefinitionName, mergeDocuments} from 'coral-framework/utils'; -import {getGraphQLConfigs} from 'coral-framework/helpers/plugins'; +import {getGraphQLExtensions} from 'coral-framework/helpers/plugins'; import globalFragments from 'coral-framework/graphql/fragments'; import uniq from 'lodash/uniq'; @@ -10,16 +10,16 @@ const queryOptions = {}; const getTypeName = (ast) => ast.definitions[0].typeCondition.name.value; /** - * Register fragment + * Add fragment * * Example: - * registerFragment('MyFragment', gql` + * addFragment('MyFragment', gql` * fragment Plugin_MyFragment on Comment { * body * } * `); */ -export function registerFragment(key, document) { +export function addFragment(key, document) { const type = getTypeName(document); const name = getDefinitionName(document); if (!(key in fragments)) { @@ -34,12 +34,12 @@ export function registerFragment(key, document) { } /** - * Register mutation options. + * Add mutation options. * * Example: * // state is the current redux state, which is sometimes * // necessary to fill the optimistic response. - * registerMutationOptions('PostComment', ({variables, state}) => ({ + * addMutationOptions('PostComment', ({variables, state}) => ({ * optimisticResponse: { * CreateComment: { * extra: '', @@ -55,7 +55,7 @@ export function registerFragment(key, document) { * }, * }) */ -export function registerMutationOptions(key, config) { +export function addMutationOptions(key, config) { if (!(key in mutationOptions)) { mutationOptions[key] = [config]; } else { @@ -64,14 +64,14 @@ export function registerMutationOptions(key, config) { } /** - * Register query options. + * Add query options. * * Example: - * registerQueryOptions('EmbedQuery', { + * addQueryOptions('EmbedQuery', { * reducer: (previousResult, action, variables) => previousResult, * }); */ -export function registerQueryOptions(key, config) { +export function addQueryOptions(key, config) { if (!(key in queryOptions)) { queryOptions[key] = [config]; } else { @@ -80,10 +80,10 @@ export function registerQueryOptions(key, config) { } /** - * Register all fragments, mutation options, and query options defined in the object. + * Add all fragments, mutation options, and query options defined in the object. * * Example: - * registerConfig({ + * add({ * fragments: { * CreateCommentResponse: gql` * fragment CoralRandomEmoji_CreateCommentResponse on CreateCommentResponse { @@ -116,10 +116,10 @@ export function registerQueryOptions(key, config) { * }, * }); */ -export function registerConfig(cfg) { - Object.keys(cfg.fragments || []).forEach(key => registerFragment(key, cfg.fragments[key])); - Object.keys(cfg.mutations || []).forEach(key => registerMutationOptions(key, cfg.mutations[key])); - Object.keys(cfg.queries || []).forEach(key => registerQueryOptions(key, cfg.queries[key])); +export function add(extension) { + Object.keys(extension.fragments || []).forEach(key => addFragment(key, extension.fragments[key])); + Object.keys(extension.mutations || []).forEach(key => addMutationOptions(key, extension.mutations[key])); + Object.keys(extension.queries || []).forEach(key => addQueryOptions(key, extension.queries[key])); } /** @@ -140,7 +140,7 @@ export function getQueryOptions(key) { /** * Get a document with a fragment named `key`, which contains - * all fragments registered under this key. + * all fragments added under this key. */ export function getFragmentDocument(key) { init(); @@ -162,20 +162,20 @@ export function getFragmentDocument(key) { } // The fragments and configs are lazily loaded to allow circular dependencies to work. -// TODO: We might want to change this to an explicit register after we have lazy Queries and Mutations. +// TODO: We might want to change this to an explicit add after we have lazy Queries and Mutations. let initialized = false; function init() { if (initialized) { return; } initialized = true; - // Register fragments from framework. + // Add fragments from framework. [globalFragments].forEach(map => - Object.keys(map).forEach(key => registerFragment(key, map[key])) + Object.keys(map).forEach(key => addFragment(key, map[key])) ); - // Register configs from plugins. - getGraphQLConfigs().forEach(cfg => registerConfig(cfg)); + // Add configs from plugins. + getGraphQLExtensions().forEach(ext => add(ext)); } export function resolveFragments(document) {