graphql#StringValueNode TypeScript Examples

The following examples show how to use graphql#StringValueNode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: swift-declaration-block.ts    From amplify-codegen with Apache License 2.0 6 votes vote down vote up
function transformComment(comment: string | StringValueNode, indentLevel = 0): string {
  if (isStringValueNode(comment)) {
    comment = comment.value;
  }

  if (!comment || comment === '') {
    return '';
  }

  const lines = comment.split('\n');

  return lines
    .map((line, index) => {
      const isLast = lines.length === index + 1;
      const isFirst = index === 0;

      if (isFirst && isLast) {
        return indent(`// ${comment} \n`, indentLevel);
      }
      line = line.split('*/').join('*\\/');
      return indent(`${isFirst ? '/*' : ''} * ${line}${isLast ? '\n */\n' : ''}`, indentLevel);
    })
    .join('\n');
}
Example #2
Source File: typescript-declaration-block.ts    From amplify-codegen with Apache License 2.0 6 votes vote down vote up
function transformComment(comment: string | StringValueNode, indentLevel = 0): string {
  if (!comment || comment === '') {
    return '';
  }

  if (isStringValueNode(comment)) {
    comment = comment.value;
  }

  comment = comment.split('*/').join('*\\/');
  const lines = comment.split('\n');

  return lines
    .map((line, index) => {
      const isLast = lines.length === index + 1;
      const isFirst = index === 0;

      if (isFirst && isLast) {
        return indent(`// ${comment} */\n`, indentLevel);
      }

      return indent(`${isFirst ? '/*' : ''} * ${line}${isLast ? '\n */\n' : ''}`, indentLevel);
    })
    .join('\n');
}
Example #3
Source File: description-style.ts    From graphql-eslint with MIT License 5 votes vote down vote up
rule: GraphQLESLintRule<[DescriptionStyleRuleConfig]> = {
  meta: {
    type: 'suggestion',
    hasSuggestions: true,
    docs: {
      examples: [
        {
          title: 'Incorrect',
          usage: [{ style: 'inline' }],
          code: /* GraphQL */ `
            """ Description """
            type someTypeName {
              # ...
            }
          `,
        },
        {
          title: 'Correct',
          usage: [{ style: 'inline' }],
          code: /* GraphQL */ `
            " Description "
            type someTypeName {
              # ...
            }
          `,
        },
      ],
      description: 'Require all comments to follow the same style (either block or inline).',
      category: 'Schema',
      url: 'https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/description-style.md',
      recommended: true,
    },
    schema: [
      {
        type: 'object',
        additionalProperties: false,
        properties: {
          style: {
            enum: ['block', 'inline'],
            default: 'block',
          },
        },
      },
    ],
  },
  create(context) {
    const { style = 'block' } = context.options[0] || {};
    const isBlock = style === 'block';
    return {
      [`.description[type=StringValue][block!=${isBlock}]`](node: GraphQLESTreeNode<StringValueNode>) {
        context.report({
          loc: isBlock ? node.loc : node.loc.start,
          message: `Unexpected ${isBlock ? 'inline' : 'block'} description.`,
          suggest: [
            {
              desc: `Change to ${isBlock ? 'block' : 'inline'} style description`,
              fix(fixer) {
                const sourceCode = context.getSourceCode();
                const originalText = sourceCode.getText(node as any);
                const newText = isBlock
                  ? originalText.replace(/(^")|("$)/g, '"""')
                  : originalText.replace(/(^""")|("""$)/g, '"').replace(/\s+/g, ' ');
                return fixer.replaceText(node as any, newText);
              },
            },
          ],
        });
      },
    };
  },
}
Example #4
Source File: generate-query.ts    From graphql-query-generator with MIT License 5 votes vote down vote up
/**
 * Returns the first slicing argument defined in the field's @listSize
 * directive, if:
 *  - The @listSize directive is indeed present, and defines slicing arguments
 *  - The requiredArguments do not already include any of the defined slicing
 *    arguments
 *  - The @listSize directive doesn't also set requireOneSlicingArgument to
 *    false
 *
 * TODO: add link to specification / documentation of @listSize directive
 */
function getMissingSlicingArg(
  requiredArguments: InputValueDefinitionNode[],
  field: FieldDefinitionNode,
  schema: GraphQLSchema
): InputValueDefinitionNode {
  // Return null if there is no @listSize directive:
  const listSizeDirective = getListSizeDirective(field)
  if (!listSizeDirective) return null

  // Return null if @listSize directive defines no slicing arguments:
  const slicingArgumentsArg = getSlicingArguments(listSizeDirective)
  if (!slicingArgumentsArg) return null

  // Return null if requireOneSlicingArgument is set to false:
  const requireOneSlicingArg = getRequireOneSlicingArgument(listSizeDirective)
  if (
    requireOneSlicingArg &&
    (requireOneSlicingArg.value as BooleanValueNode).value === false // already checked requireOneSlicingArg is a boolean
  )
    return null

  // Return null if a slicing argument is already used:
  const slicingArguments = (slicingArgumentsArg.value as ListValueNode).values // already checked slicingArgumentsArg is a list
    .filter((value) => value.kind === 'StringValue')
    .map((value) => (value as StringValueNode).value)
  const usesSlicingArg = slicingArguments.some((slicingArg) =>
    requiredArguments
      .map((existing) => existing.name.value)
      .includes(slicingArg)
  )
  if (usesSlicingArg) return null

  // Returns the first slicing argument if slicing argument can be split on '.'
  // then we just need to check the first level match
  return field.arguments.find((arg) => {
    return slicingArguments.find((slicingArgument) => {
      const tokenizedPath = slicingArgument.split('.')
      if (tokenizedPath.length < 1) return false

      return arg.name.value === tokenizedPath[0]
    })
  })
}
Example #5
Source File: dart-declaration-block.ts    From amplify-codegen with Apache License 2.0 5 votes vote down vote up
withComment(comment: string | StringValueNode | null): DartDeclarationBlock {
    if(comment) {
        this._comment = transformComment(comment, 0);
    }
    return this;
  }
Example #6
Source File: java-declaration-block.ts    From amplify-codegen with Apache License 2.0 5 votes vote down vote up
withComment(comment: string | StringValueNode | null): JavaDeclarationBlock {
    if (comment) {
      this._comment = transformComment(comment, 0);
    }

    return this;
  }
Example #7
Source File: swift-declaration-block.ts    From amplify-codegen with Apache License 2.0 5 votes vote down vote up
withComment(comment: string | StringValueNode | null): SwiftDeclarationBlock {
    if (comment) {
      this._comment = transformComment(comment, 0);
    }
    return this;
  }
Example #8
Source File: swift-declaration-block.ts    From amplify-codegen with Apache License 2.0 5 votes vote down vote up
function isStringValueNode(node: any): node is StringValueNode {
  return node && typeof node === 'object' && node.kind === 'StringValue';
}
Example #9
Source File: typescript-declaration-block.ts    From amplify-codegen with Apache License 2.0 5 votes vote down vote up
public withComment(comment: string | StringValueNode): TypeScriptDeclarationBlock {
    this._comments = transformComment(comment);
    return this;
  }
Example #10
Source File: typescript-declaration-block.ts    From amplify-codegen with Apache License 2.0 5 votes vote down vote up
function isStringValueNode(node: any): node is StringValueNode {
  return node && typeof node === 'object' && node.kind === 'StringValue';
}