Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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]));
});
});
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
})
})
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',
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),
});
}
}
},
});
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);
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 }));
});
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;
}
function getTypeFromAST(schema: GraphQLSchema, ast: TypeNode): GraphQLType {
const type = typeFromAST(schema, ast);
invariant(isType(type), 'GraphQLSchemaUtils: Unknown type `%s`.', print(ast));
return (type: any);
}
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))}
\`\`\``
)
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,
}));