How to use the graphql.print function in graphql

To help you get started, we’ve selected a few graphql 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 apollographql / persistgraphql / test / extractFromAST.ts View on Github external
author {
            firstName
            lastName
          }
        }
      `;
      const query2 = gql`
        query {
          person {
            name
          }
        }`;
      const queries = getQueryDefinitions(document);
      assert.equal(queries.length, 2);
      assert.equal(print(queries[0]), print(query1.definitions[0]));
      assert.equal(print(queries[1]), print(query2.definitions[0]));
    });
  });
github prisma-labs / prisma-binding / src / link.ts View on Github external
const debugLink = new ApolloLink((operation, forward) => {
      console.log(`Request to ${endpoint}:`)
      console.log(`query:`)
      console.log(print(operation.query).trim())
      console.log(`operationName: ${operation.operationName}`)
      console.log(`variables:`)
      console.log(JSON.stringify(operation.variables, null, 2))

      return forward!(operation).map(data => {
        console.log(`Response from ${endpoint}:`)
        console.log(JSON.stringify(data.data, null, 2))
        return data
      })
    })
github apollographql / apollo-server / packages / apollo-server-core / src / logging.ts View on Github external
public requestDidStart(options: {
    request: Request;
    queryString?: string;
    parsedQuery?: DocumentNode;
    operationName?: string;
    variables?: { [key: string]: any };
  }) {
    this.logFunction({ action: LogAction.request, step: LogStep.start });
    const loggedQuery = options.queryString || print(options.parsedQuery);
    this.logFunction({
      action: LogAction.request,
      step: LogStep.status,
      key: 'query',
      data: loggedQuery,
    });
    this.logFunction({
      action: LogAction.request,
      step: LogStep.status,
      key: 'variables',
      data: options.variables,
    });
    this.logFunction({
      action: LogAction.request,
      step: LogStep.status,
      key: 'operationName',
github graphql / graphiql / packages / graphiql / src / utility / fillLeafs.js View on Github external
enter(node) {
      typeInfo.enter(node);
      if (node.kind === 'Field' && !node.selectionSet) {
        const fieldType = typeInfo.getType();
        const selectionSet = buildSelectionSet(fieldType, fieldNameFn);
        if (selectionSet) {
          const indent = getIndentation(docString, node.loc.start);
          insertions.push({
            index: node.loc.end,
            string: ' ' + print(selectionSet).replace(/\n/g, '\n' + indent),
          });
        }
      }
    },
  });
github graphql / graphiql / packages / graphiql / src / components / GraphiQL.js View on Github external
handlePrettifyQuery = () => {
    const editor = this.getQueryEditor();
    const editorContent = editor.getValue();
    const prettifiedEditorContent = print(parse(editorContent));

    if (prettifiedEditorContent !== editorContent) {
      editor.setValue(prettifiedEditorContent);
    }

    const variableEditor = this.getVariableEditor();
    const variableEditorContent = variableEditor.getValue();

    try {
      const prettifiedVariableEditorContent = JSON.stringify(
        JSON.parse(variableEditorContent),
        null,
        2
      );
      if (prettifiedVariableEditorContent !== variableEditorContent) {
        variableEditor.setValue(prettifiedVariableEditorContent);
github FormidableLabs / urql-devtools / src / panel / context / Request.tsx View on Github external
const schema = await introspectSchema(({ query, variables }) => {
          return fetch(endpoint, {
            method: "POST",
            headers: {
              "content-type": "application/json"
            },
            body: JSON.stringify({ query: print(query), variables })
          })
            .then(data => data.json())
            .catch(error => ({ data: null, error }));
        });
github grafoojs / grafoo / packages / babel-plugin / src / compile-document.js View on Github external
if (a.value && a.value.kind === "Variable") {
                a = a.value;
              }
              return a.name.value;
            })
          }
        }),
      {}
    );
  }

  if (frags.length) {
    grafooObj.frags = {};

    for (const frag of frags) {
      grafooObj.frags[frag.name.value] = opts.compress ? compress(print(frag)) : print(frag);
    }
  }

  return grafooObj;
}
github facebook / relay / packages / relay-compiler / graphql-compiler / core / GraphQLSchemaUtils.js View on Github external
function getTypeFromAST(schema: GraphQLSchema, ast: TypeNode): GraphQLType {
  const type = typeFromAST(schema, ast);
  invariant(isType(type), 'GraphQLSchemaUtils: Unknown type `%s`.', print(ast));
  return (type: any);
}
github ArcBlock / forge-js / forge / graphql-client / tools / generate-queries.js View on Github external
Object.values(method.args).length
    ? Object.values(method.args)
        .map(
          arg =>
            `* **${arg.name}**, ${arg.type.kind === 'NON_NULL' ? '**required**' : 'optional'}, ${
              arg.description
            }`
        )
        .join('\n')
    : 'No arguments'
}

#### Result Format

\`\`\`graphql
${print(parse(method.result))}
\`\`\``
        )
github gajus / format-graphql / src / utilities / formatSdl.js View on Github external
export default (schemaSdl: string): string => {
  return print(mapObject(parse(schemaSdl), (key, value) => {
    if ((key === 'fields' || key === 'definitions') && Array.isArray(value)) {
      return [
        key,
        value.slice().sort((a, b) => {
          return a.name.value.localeCompare(b.name.value);
        }),
      ];
    }

    return [
      key,
      value,
    ];
  }, {
    deep: true,
  }));