Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Initial documentation descriptions for generated API #515

Merged
merged 3 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/augment/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,19 @@ export const buildDirectiveDefinition = ({
};
};

export const buildDescription = ({ value, block = false }) => ({
kind: Kind.STRING,
value,
block
});
export const buildDescription = ({ value, block = false, config = {} }) => {
// If boolean and not false, then default is to generate documentation
if (
typeof config.documentation !== 'boolean' ||
config.documentation !== false
) {
return {
kind: Kind.STRING,
value,
block
};
}
};

export const buildSelectionSet = ({ selections = [] }) => {
return {
Expand Down
11 changes: 9 additions & 2 deletions src/augment/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
OperationType
} from './types/types';
import { OrderingArgument, buildPropertyOrderingValues } from './input-values';
import { buildField, buildName, buildNamedType } from './ast';
import { buildField, buildName, buildNamedType, buildDescription } from './ast';

/**
* The name of the Neo4j system ID field
Expand Down Expand Up @@ -194,7 +194,8 @@ export const buildNeo4jSystemIDField = ({
typeName,
propertyOutputFields,
nodeInputTypeMap,
config
config,
isRelationship = false
}) => {
const queryTypeNameLower = OperationType.QUERY.toLowerCase();
if (shouldAugmentType(config, queryTypeNameLower, typeName)) {
Expand All @@ -207,10 +208,16 @@ export const buildNeo4jSystemIDField = ({
const systemIDIndex = propertyOutputFields.findIndex(
e => e.name.value === Neo4jSystemIDField
);
let entityDescription = 'node';
if (isRelationship) entityDescription = 'relationship';
const systemIDField = buildField({
name: buildName({ name: neo4jInternalIDConfig.name }),
type: buildNamedType({
name: GraphQLString.name
}),
description: buildDescription({
value: `Generated field for querying the Neo4j [system id](https://neo4j.com/docs/cypher-manual/current/functions/scalar/#functions-id) of this ${entityDescription}.`,
config
})
});
if (systemIDIndex >= 0) {
Expand Down
37 changes: 29 additions & 8 deletions src/augment/types/node/mutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
buildField,
buildName,
buildNamedType,
buildInputValue
buildInputValue,
buildDescription
} from '../../ast';
import {
DirectiveDefinition,
Expand Down Expand Up @@ -32,6 +33,9 @@ const NodeMutation = {
MERGE: 'Merge'
};

const GRANDSTACK_DOCS = `https://grandstack.io/docs`;
const GRANDSTACK_DOCS_SCHEMA_AUGMENTATION = `${GRANDSTACK_DOCS}/graphql-schema-generation-augmentation`;

/**
* Given the results of augmentNodeTypeFields, builds or augments
* the AST definitions of the Mutation operation fields and any
Expand Down Expand Up @@ -84,7 +88,7 @@ export const augmentNodeMutationAPI = ({
*/
const buildNodeMutationField = ({
mutationType,
mutationAction,
mutationAction = '',
primaryKey,
typeName,
propertyInputValues,
Expand All @@ -106,7 +110,7 @@ const buildNodeMutationField = ({
name: typeName
})
) {
const mutationField = {
const mutationConfig = {
name: buildName({ name: mutationName }),
args: buildNodeMutationArguments({
operationName: mutationAction,
Expand All @@ -122,21 +126,38 @@ const buildNodeMutationField = ({
config
})
};
let mutationField = undefined;
let mutationDescriptionUrl = '';
if (mutationAction === NodeMutation.CREATE) {
mutationFields.push(buildField(mutationField));
mutationField = mutationConfig;
mutationDescriptionUrl =
'[creating](https://neo4j.com/docs/cypher-manual/4.1/clauses/create/#create-nodes)';
} else if (mutationAction === NodeMutation.UPDATE) {
if (primaryKey && mutationField.args.length > 1) {
mutationFields.push(buildField(mutationField));
if (primaryKey && mutationConfig.args.length > 1) {
mutationField = mutationConfig;
mutationDescriptionUrl =
'[updating](https://neo4j.com/docs/cypher-manual/4.1/clauses/set/#set-update-a-property)';
}
} else if (mutationAction === NodeMutation.MERGE) {
if (primaryKey) {
mutationFields.push(buildField(mutationField));
mutationField = mutationConfig;
mutationDescriptionUrl =
'[merging](https://neo4j.com/docs/cypher-manual/4.1/clauses/merge/#query-merge-node-derived)';
}
} else if (mutationAction === NodeMutation.DELETE) {
if (primaryKey) {
mutationFields.push(buildField(mutationField));
mutationField = mutationConfig;
mutationDescriptionUrl =
'[deleting](https://neo4j.com/docs/cypher-manual/4.1/clauses/delete/#delete-delete-single-node)';
}
}
if (mutationField) {
mutationField.description = buildDescription({
value: `[Generated mutation](${GRANDSTACK_DOCS_SCHEMA_AUGMENTATION}/#${mutationAction.toLowerCase()}) for ${mutationDescriptionUrl} a ${typeName} node.`,
config
});
mutationFields.push(buildField(mutationField));
}
operationTypeMap[OperationType.MUTATION].fields = mutationFields;
}
return operationTypeMap;
Expand Down
13 changes: 10 additions & 3 deletions src/augment/types/node/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
buildField,
buildInputValue,
buildName,
buildNamedType
buildNamedType,
buildDescription
} from '../../ast';
import {
DirectiveDefinition,
Expand All @@ -18,8 +19,7 @@ import {
getFieldDefinition,
getTypeExtensionFieldDefinition,
isNeo4jIDField,
Neo4jSystemIDField,
isListTypeField
Neo4jSystemIDField
} from '../../fields';
import {
FilteringArgument,
Expand All @@ -40,6 +40,9 @@ const NodeQueryArgument = {
...FilteringArgument
};

const GRANDSTACK_DOCS = `https://grandstack.io/docs`;
const GRANDSTACK_DOCS_GENERATED_QUERIES = `${GRANDSTACK_DOCS}/graphql-schema-generation-augmentation#generated-queries`;

/**
* Given the results of augmentNodeTypeFields, builds or augments
* the AST definition of the Query operation field and any
Expand Down Expand Up @@ -190,6 +193,10 @@ const buildNodeQueryField = ({
directives: buildNodeQueryDirectives({
typeName,
config
}),
description: buildDescription({
value: `[Generated query](${GRANDSTACK_DOCS_GENERATED_QUERIES}) for ${typeName} type nodes.`,
config
})
})
);
Expand Down
67 changes: 62 additions & 5 deletions src/augment/types/relationship/mutation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { RelationshipDirectionField } from './relationship';
import { buildNodeOutputFields } from './query';
import { shouldAugmentRelationshipField } from '../../augment';
import { OperationType } from '../../types/types';
import {
Expand All @@ -23,7 +22,8 @@ import {
buildNamedType,
buildField,
buildObjectType,
buildInputObjectType
buildInputObjectType,
buildDescription
} from '../../ast';
import { getPrimaryKey } from '../node/selection';
import { isExternalTypeExtension } from '../../../federation';
Expand All @@ -40,6 +40,10 @@ const RelationshipMutation = {
MERGE: 'Merge'
};

const GRANDSTACK_DOCS = `https://grandstack.io/docs`;
const GRANDSTACK_DOCS_RELATIONSHIP_TYPE_QUERY = `${GRANDSTACK_DOCS}/graphql-relationship-types`;
const GRANDSTACK_DOCS_SCHEMA_AUGMENTATION = `${GRANDSTACK_DOCS}/graphql-schema-generation-augmentation`;

/**
* Given the results of augmentRelationshipTypeFields, builds or
* augments the AST definitions of the Mutation operation fields
Expand Down Expand Up @@ -242,7 +246,8 @@ const buildRelationshipMutationAPI = ({
relationshipName,
fromType,
toType,
generatedTypeMap
generatedTypeMap,
config
});
}
return [operationTypeMap, generatedTypeMap];
Expand Down Expand Up @@ -272,6 +277,28 @@ const buildRelationshipMutationField = ({
propertyInputValues.length) ||
mutationAction === RelationshipMutation.MERGE
) {
let cypherDocUrl = '';
let grandstackDocUrl = '';
if (mutationAction === RelationshipMutation.CREATE) {
cypherDocUrl =
'[creating](https://neo4j.com/docs/cypher-manual/4.1/clauses/create/#create-relationships)';
grandstackDocUrl = '#add--remove-relationship';
}
if (mutationAction === RelationshipMutation.DELETE) {
cypherDocUrl =
'[deleting](https://neo4j.com/docs/cypher-manual/4.1/clauses/delete/#delete-delete-relationships-only)';
grandstackDocUrl = '#add--remove-relationship';
}
if (mutationAction === RelationshipMutation.UPDATE) {
cypherDocUrl =
'[updating](https://neo4j.com/docs/cypher-manual/4.1/clauses/set/#set-update-a-property)';
grandstackDocUrl = '#update-relationship';
}
if (mutationAction === RelationshipMutation.MERGE) {
cypherDocUrl =
'[merging](https://neo4j.com/docs/cypher-manual/4.1/clauses/merge/#query-merge-relationships)';
grandstackDocUrl = '#merge-relationship';
}
operationTypeMap[OperationType.MUTATION].fields.push(
buildField({
name: buildName({
Expand All @@ -293,6 +320,10 @@ const buildRelationshipMutationField = ({
fromType,
toType,
config
}),
description: buildDescription({
value: `[Generated mutation](${GRANDSTACK_DOCS_SCHEMA_AUGMENTATION}/#${grandstackDocUrl.toLowerCase()}) for ${cypherDocUrl} the ${relationshipName} relationship.`,
config
})
})
);
Expand Down Expand Up @@ -444,7 +475,8 @@ const buildRelationshipMutationOutputType = ({
relationshipName,
fromType,
toType,
generatedTypeMap
generatedTypeMap,
config
}) => {
if (
mutationAction === RelationshipMutation.CREATE ||
Expand All @@ -458,7 +490,32 @@ const buildRelationshipMutationOutputType = ({
fromType,
toType
});
let fields = buildNodeOutputFields({ fromType, toType });
let fields = [
buildField({
name: buildName({
name: RelationshipDirectionField.FROM
}),
type: buildNamedType({
name: fromType
}),
description: buildDescription({
value: `Field for the ${fromType} node this ${relationshipName} [relationship](${GRANDSTACK_DOCS_RELATIONSHIP_TYPE_QUERY}) is coming from.`,
config
})
}),
buildField({
name: buildName({
name: RelationshipDirectionField.TO
}),
type: buildNamedType({
name: toType
}),
description: buildDescription({
value: `Field for the ${toType} node this ${relationshipName} [relationship](${GRANDSTACK_DOCS_RELATIONSHIP_TYPE_QUERY}) is going to.`,
config
})
})
];
if (
mutationAction === RelationshipMutation.CREATE ||
mutationAction === RelationshipMutation.UPDATE ||
Expand Down
Loading