當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript graphql.GraphQLObjectType類代碼示例

本文整理匯總了TypeScript中graphql.GraphQLObjectType的典型用法代碼示例。如果您正苦於以下問題:TypeScript GraphQLObjectType類的具體用法?TypeScript GraphQLObjectType怎麽用?TypeScript GraphQLObjectType使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了GraphQLObjectType類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: addFakeProperties

  function addFakeProperties(objectType:GraphQLObjectType) {
    const isMutation = (objectType.name === mutationTypeName);

    for (let field of Object.values(objectType.getFields())) {
      if (isMutation && isRelayMutation(field))
        field.resolve = getRelayMutationResolver();
      else
        field.resolve = getFieldResolver(field);
    }
  }
開發者ID:codeaudit,項目名稱:graphql-faker,代碼行數:10,代碼來源:fake_schema.ts

示例2: getTypesAndWhere

export function getTypesAndWhere(queryType: GraphQLObjectType) {
  const fields = queryType.getFields()
  const listFields = Object.keys(fields).reduce(
    (acc, field) => {
      const deepType = getDeepListType(fields[field])
      if (deepType) {
        acc.push({ field: fields[field], deepType })
      }
      return acc
    },
    [] as any[],
  )

  return listFields.map(({ field, deepType }) => ({
    type: deepType.name,
    pluralFieldName: field.name,
    where: getWhere(field),
  }))
}
開發者ID:dhruvcodeword,項目名稱:prisma,代碼行數:19,代碼來源:index.ts

示例3: generateMappingFromObjectType

export function generateMappingFromObjectType(
  type: GraphQLObjectType,
  operation: Operation,
): {
  [fieldName: string]: {
    name: string;
    operation: Operation;
  };
} {
  const result = {};
  const fields = type.getFields();
  Object.keys(fields).forEach(fieldName => {
    result[fieldName] = {
      name: fieldName,
      operation,
    };
  });
  return result;
}
開發者ID:apollostack,項目名稱:graphql-tools,代碼行數:19,代碼來源:resolvers.ts

示例4: createDocument

function createDocument(
  schema: GraphQLSchema,
  fragmentReplacements: {
    [typeName: string]: { [fieldName: string]: InlineFragmentNode };
  },
  type: GraphQLObjectType,
  rootFieldName: string,
  operation: 'query' | 'mutation',
  selections: Array<FieldNode>,
  fragments: { [fragmentName: string]: FragmentDefinitionNode },
  variableDefinitions?: Array<VariableDefinitionNode>,
): DocumentNode {
  const rootField = type.getFields()[rootFieldName];
  const newVariables: Array<{ arg: string; variable: string }> = [];
  const rootSelectionSet = {
    kind: Kind.SELECTION_SET,
    // (XXX) This (wrongly) assumes only having one fieldNode
    selections: selections.map(selection => {
      if (selection.kind === Kind.FIELD) {
        const { selection: newSelection, variables } = processRootField(
          selection,
          rootFieldName,
          rootField,
        );
        newVariables.push(...variables);
        return newSelection;
      } else {
        return selection;
      }
    }),
  };

  const newVariableDefinitions = newVariables.map(({ arg, variable }) => {
    const argDef = rootField.args.find(rootArg => rootArg.name === arg);
    if (!argDef) {
      throw new Error('Unexpected missing arg');
    }
    const typeName = typeToAst(argDef.type);
    return {
      kind: Kind.VARIABLE_DEFINITION,
      variable: {
        kind: Kind.VARIABLE,
        name: {
          kind: Kind.NAME,
          value: variable,
        },
      },
      type: typeName,
    };
  });

  const {
    selectionSet,
    fragments: processedFragments,
    usedVariables,
  } = filterSelectionSetDeep(
    schema,
    fragmentReplacements,
    type,
    rootSelectionSet,
    fragments,
  );

  const operationDefinition: OperationDefinitionNode = {
    kind: Kind.OPERATION_DEFINITION,
    operation,
    variableDefinitions: [
      ...(variableDefinitions || []).filter(
        variableDefinition =>
          usedVariables.indexOf(variableDefinition.variable.name.value) !== -1,
      ),
      ...newVariableDefinitions,
    ],
    selectionSet,
  };

  const newDoc: DocumentNode = {
    kind: Kind.DOCUMENT,
    definitions: [operationDefinition, ...processedFragments],
  };

  return newDoc;
}
開發者ID:sventschui,項目名稱:graphql-tools,代碼行數:83,代碼來源:mergeSchemas.ts

示例5: while

  const newOperations = operations.map((operation: OperationDefinitionNode) => {
    let existingVariables = operation.variableDefinitions.map(
      (variableDefinition: VariableDefinitionNode) =>
        variableDefinition.variable.name.value,
    );

    let variableCounter = 0;
    const variables = {};

    const generateVariableName = (argName: string) => {
      let varName;
      do {
        varName = `_v${variableCounter}_${argName}`;
        variableCounter++;
      } while (existingVariables.indexOf(varName) !== -1);
      return varName;
    };

    let type: GraphQLObjectType;
    if (operation.operation === 'subscription') {
      type = targetSchema.getSubscriptionType();
    } else if (operation.operation === 'mutation') {
      type = targetSchema.getMutationType();
    } else {
      type = targetSchema.getQueryType();
    }

    const newSelectionSet: Array<SelectionNode> = [];

    operation.selectionSet.selections.forEach((selection: SelectionNode) => {
      if (selection.kind === Kind.FIELD) {
        let newArgs: { [name: string]: ArgumentNode } = {};
        selection.arguments.forEach((argument: ArgumentNode) => {
          newArgs[argument.name.value] = argument;
        });
        const name: string = selection.name.value;
        const field: GraphQLField<any, any> = type.getFields()[name];
        field.args.forEach((argument: GraphQLArgument) => {
          if (argument.name in args) {
            const variableName = generateVariableName(argument.name);
            variableNames[argument.name] = variableName;
            newArgs[argument.name] = {
              kind: Kind.ARGUMENT,
              name: {
                kind: Kind.NAME,
                value: argument.name,
              },
              value: {
                kind: Kind.VARIABLE,
                name: {
                  kind: Kind.NAME,
                  value: variableName,
                },
              },
            };
            existingVariables.push(variableName);
            variables[variableName] = {
              kind: Kind.VARIABLE_DEFINITION,
              variable: {
                kind: Kind.VARIABLE,
                name: {
                  kind: Kind.NAME,
                  value: variableName,
                },
              },
              type: typeToAst(argument.type),
            };
          }
        });

        newSelectionSet.push({
          ...selection,
          arguments: Object.keys(newArgs).map(argName => newArgs[argName]),
        });
      } else {
        newSelectionSet.push(selection);
      }
    });

    return {
      ...operation,
      variableDefinitions: operation.variableDefinitions.concat(
        Object.keys(variables).map(varName => variables[varName]),
      ),
      selectionSet: {
        kind: Kind.SELECTION_SET,
        selections: newSelectionSet,
      },
    };
  });
開發者ID:apollostack,項目名稱:graphql-tools,代碼行數:90,代碼來源:AddArgumentsAsVariables.ts

示例6: generateVariableName

    operation.selectionSet.selections.forEach((selection: SelectionNode) => {
      if (selection.kind === Kind.FIELD) {
        let newArgs: { [name: string]: ArgumentNode } = {};
        selection.arguments.forEach((argument: ArgumentNode) => {
          newArgs[argument.name.value] = argument;
        });
        const name: string = selection.name.value;
        const field: GraphQLField<any, any> = type.getFields()[name];
        field.args.forEach((argument: GraphQLArgument) => {
          if (argument.name in args) {
            const variableName = generateVariableName(argument.name);
            variableNames[argument.name] = variableName;
            newArgs[argument.name] = {
              kind: Kind.ARGUMENT,
              name: {
                kind: Kind.NAME,
                value: argument.name,
              },
              value: {
                kind: Kind.VARIABLE,
                name: {
                  kind: Kind.NAME,
                  value: variableName,
                },
              },
            };
            existingVariables.push(variableName);
            variables[variableName] = {
              kind: Kind.VARIABLE_DEFINITION,
              variable: {
                kind: Kind.VARIABLE,
                name: {
                  kind: Kind.NAME,
                  value: variableName,
                },
              },
              type: typeToAst(argument.type),
            };
          }
        });

        newSelectionSet.push({
          ...selection,
          arguments: Object.keys(newArgs).map(argName => newArgs[argName]),
        });
      } else {
        newSelectionSet.push(selection);
      }
    });
開發者ID:apollostack,項目名稱:graphql-tools,代碼行數:49,代碼來源:AddArgumentsAsVariables.ts


注:本文中的graphql.GraphQLObjectType類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。