How to use the @graphql-codegen/visitor-plugin-common.getBaseTypeNode function in @graphql-codegen/visitor-plugin-common

To help you get started, we’ve selected a few @graphql-codegen/visitor-plugin-common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dotansimha / graphql-code-generator / packages / plugins / java / kotlin / src / visitor.ts View on Github external
protected resolveInputFieldType(typeNode: TypeNode): { baseType: string; typeName: string; isScalar: boolean; isArray: boolean; nullable: boolean } {
    const innerType = getBaseTypeNode(typeNode);
    const schemaType = this._schema.getType(innerType.name.value);
    const isArray = typeNode.kind === Kind.LIST_TYPE || (typeNode.kind === Kind.NON_NULL_TYPE && typeNode.type.kind === Kind.LIST_TYPE);
    let result: { baseType: string; typeName: string; isScalar: boolean; isArray: boolean; nullable: boolean } = null;
    const nullable = typeNode.kind !== Kind.NON_NULL_TYPE;

    if (isScalarType(schemaType)) {
      if (this.config.scalars[schemaType.name]) {
        result = {
          baseType: this.scalars[schemaType.name],
          typeName: this.scalars[schemaType.name],
          isScalar: true,
          isArray,
          nullable: nullable,
        };
      } else {
        result = { isArray, baseType: 'Any', typeName: 'Any', isScalar: true, nullable: nullable };
github dotansimha / graphql-code-generator / packages / plugins / java / java / src / visitor.ts View on Github external
protected resolveInputFieldType(typeNode: TypeNode): { baseType: string; typeName: string; isScalar: boolean; isArray: boolean } {
    const innerType = getBaseTypeNode(typeNode);
    const schemaType = this._schema.getType(innerType.name.value);
    const isArray = typeNode.kind === Kind.LIST_TYPE || (typeNode.kind === Kind.NON_NULL_TYPE && typeNode.type.kind === Kind.LIST_TYPE);
    let result: { baseType: string; typeName: string; isScalar: boolean; isArray: boolean } = null;

    if (isScalarType(schemaType)) {
      if (this.scalars[schemaType.name]) {
        result = {
          baseType: this.scalars[schemaType.name],
          typeName: this.scalars[schemaType.name],
          isScalar: true,
          isArray,
        };
      } else {
        result = { isArray, baseType: 'Object', typeName: 'Object', isScalar: true };
      }
    } else if (isInputObjectType(schemaType)) {
github dotansimha / graphql-code-generator / packages / plugins / typescript / mongodb / src / visitor.ts View on Github external
private _handleColumnField(fieldNode: FieldDefinitionNode, tree: FieldsTree, columnDirective: DirectiveNode, mapPath: string | null, addOptionalSign: boolean): void {
    const overrideType = this._getDirectiveArgValue(columnDirective, 'overrideType');
    const coreType = getBaseTypeNode(fieldNode.type);
    let type: string = null;

    if (this.scalars[coreType.name.value]) {
      type = this.scalars[coreType.name.value];
    } else {
      const schemaType = this._schema.getType(coreType.name.value);

      if (isEnumType(schemaType) && this.config.enumsAsString) {
        type = this.scalars.String;
      } else {
        type = coreType.name.value;
      }
    }

    tree.addField(mapPath ? mapPath : `${fieldNode.name.value}${addOptionalSign ? '?' : ''}`, overrideType ? overrideType : this._variablesTransformer.wrapAstTypeWithModifiers(type, fieldNode.type));
  }
github dotansimha / graphql-code-generator / packages / plugins / typescript / mongodb / src / visitor.ts View on Github external
private _handleLinkField(fieldNode: FieldDefinitionNode, tree: FieldsTree, linkDirective: DirectiveNode, mapPath: string | null, addOptionalSign: boolean): void {
    const overrideType = this._getDirectiveArgValue(linkDirective, 'overrideType');
    const coreType = overrideType ? overrideType : getBaseTypeNode(fieldNode.type);
    const type = this.convertName(coreType, { suffix: this.config.dbTypeSuffix });

    tree.addField(mapPath ? mapPath : `${fieldNode.name.value}${addOptionalSign ? '?' : ''}`, this._variablesTransformer.wrapAstTypeWithModifiers(`${type}['${this.config.idFieldName}']`, fieldNode.type));
  }
github dotansimha / graphql-code-generator / packages / plugins / typescript / mongodb / src / visitor.ts View on Github external
private _handleEmbeddedField(fieldNode: FieldDefinitionNode, tree: FieldsTree, mapPath: string | null, addOptionalSign: boolean): void {
    const coreType = getBaseTypeNode(fieldNode.type);
    const type = this.convertName(coreType, { suffix: this.config.dbTypeSuffix });

    tree.addField(mapPath ? mapPath : `${fieldNode.name.value}${addOptionalSign ? '?' : ''}`, this._variablesTransformer.wrapAstTypeWithModifiers(type, fieldNode.type));
  }
github dotansimha / graphql-code-generator / packages / plugins / java / resolvers / src / visitor.ts View on Github external
return (isInterface: boolean) => {
      const baseType = getBaseTypeNode(node.type);
      const typeToUse = this.getTypeToUse(baseType);
      const wrappedType = wrapTypeWithModifiers(typeToUse, node.type, this.config.listType);

      if (isInterface) {
        return `default public DataFetcher<${wrappedType}> ${node.name.value}() { return null; }`;
      } else {
        return `public DataFetcher<${wrappedType}> ${node.name.value}();`;
      }
    };
  }
github dotansimha / graphql-code-generator / packages / plugins / java / apollo-android / src / operation-visitor.ts View on Github external
.map(v => {
    const baseTypeNode = getBaseTypeNode(v.type);
    const schemaType = this._schema.getType(baseTypeNode.name.value);
    const writerMethod = this._getWriterMethodByType(schemaType, true);

    return indent(
      `writer.${writerMethod.name}("${v.variable.name.value}", ${writerMethod.checkNull ? `${v.variable.name.value} != null ? ${v.variable.name.value}${writerMethod.useMarshaller ? '.marshaller()' : ''} : null` : v.variable.name.value});`,
      2
    );
  })
  .join('\n')}
github dotansimha / graphql-code-generator / packages / plugins / java / apollo-android / src / operation-visitor.ts View on Github external
node.variableDefinitions.map(varDec => {
        const outputType = getBaseTypeNode(varDec.type).name.value;
        const schemaType = this._schema.getType(outputType);
        const javaClass = this.getJavaClass(schemaType);
        const typeToUse = this.getListTypeNodeWrapped(javaClass, varDec.type);
        const isNonNull = varDec.type.kind === Kind.NON_NULL_TYPE;

        return {
          name: varDec.variable.name.value,
          type: typeToUse,
          annotations: [isNonNull ? 'Nonnull' : 'Nullable'],
        };
      }),
      null,