Skip to content

Commit

Permalink
Merge branch 'main' into useAsyncValidation-root-object-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jbolda authored Oct 5, 2023
2 parents bde0bbe + 7f8da52 commit dd62c62
Show file tree
Hide file tree
Showing 20 changed files with 468 additions and 207 deletions.
8 changes: 8 additions & 0 deletions plugins/graphql-backend-module-catalog/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @frontside/backstage-plugin-graphql-backend-module-catalog

## 0.1.1

### Patch Changes

- 33222ff: Update @frontside/hydraphql to 0.1.1
- Updated dependencies [33222ff]
- @frontside/backstage-plugin-graphql-backend@0.1.1

## 0.1.0

### Minor Changes
Expand Down
39 changes: 22 additions & 17 deletions plugins/graphql-backend-module-catalog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,51 @@ Some key features are currently missing. These features may change the schema in
1. `viewer` query for retrieving data for the current user.

- [GraphQL modules](#graphql-modules)
- [Catalog module](#catalog-module)
- [Relation module](#relation-module)
- [Backstage Plugins](#backstage-plugins)
- [Experimental Backend System](#experimental-backend-system)
- [Directives API](#directives-api)
- [`@relation` directive](#relation-directive)
- [Catalog Data loader](#catalog-data-loader-advanced)

## GraphQL modules

### Catalog module
This package provides two GraphQL modules:
- `Catalog` module – provides basic Catalog GraphQL types and `@relation` directive
- `Relation` module – provides only `@relation` directive

The `Catalog` module is installed just as any other Backstage Module:
[`@frontside/backstage-plugin-graphql-backend`](../graphql-backend/README.md)
### Backstage Plugins

For the [Backstage plugin system](https://backstage.io/docs/plugins/backend-plugin),
you can learn how to add GraphQL modules by checking out [GraphQL Modules](../graphql-backend/README.md#graphql-modules)
section in `@frontside/backstage-plugin-graphql-backend` package.

This package exports `Catalog` and `Relation` modules

### Experimental Backend System

For the [experimental backend system](https://backstage.io/docs/plugins/experimental-backend),
you can add them as a plugin modules:

- To use `Catalog` GraphQL module
```ts
// packages/backend/src/index.ts
import { graphqlModuleCatalog } from '@frontside/backstage-plugin-graphql-backend-module-catalog';

const backend = createBackend();

// GraphQL
backend.use(graphqlPlugin());
backend.use(graphqlModuleCatalog());
```

### Relation module

If you don't want to use basic Catalog types for some reason, but
still want to use `@relation` directive, you can install `Relation` module

- To use `Relation` GraphQL module
```ts
// packages/backend/src/index.ts
import { graphqlModuleRelationResolver } from '@frontside/backstage-plugin-graphql-backend-module-catalog';

const backend = createBackend();

// GraphQL
backend.use(graphqlPlugin());
backend.use(graphqlModuleRelationResolver());
```

If you don't want to use basic Catalog types for some reason, but
still want to use `@relation` directive, you can install `Relation` module

## Directives API

### `@relation`
Expand Down
6 changes: 3 additions & 3 deletions plugins/graphql-backend-module-catalog/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@frontside/backstage-plugin-graphql-backend-module-catalog",
"description": "Backstage GraphQL backend module that adds catalog schema",
"version": "0.1.0",
"version": "0.1.1",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
Expand Down Expand Up @@ -45,8 +45,8 @@
"@backstage/catalog-client": "^1.4.3",
"@backstage/catalog-model": "^1.4.1",
"@backstage/plugin-catalog-node": "^1.4.3",
"@frontside/backstage-plugin-graphql-backend": "^0.1.0",
"@frontside/hydraphql": "^0.0.1",
"@frontside/backstage-plugin-graphql-backend": "^0.1.1",
"@frontside/hydraphql": "^0.1.1",
"@graphql-tools/load-files": "^7.0.0",
"@graphql-tools/utils": "^10.0.0",
"dataloader": "^2.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ exports[`graphql-catalog codegen should generate the correct code: graphql 1`] =

directive @discriminationAlias(type: String!, value: String!) repeatable on INTERFACE

directive @field(at: _DirectiveArgument_!, default: _DirectiveArgument_) on FIELD_DEFINITION
directive @field(at: _DirectiveArgument_, default: _DirectiveArgument_) on FIELD_DEFINITION

directive @implements(interface: String!) on INTERFACE | OBJECT

directive @relation(kind: String, name: String, nodeType: String) on FIELD_DEFINITION

directive @resolve(at: _DirectiveArgument_, from: String) on FIELD_DEFINITION
directive @resolve(at: _DirectiveArgument_, from: String, nodeType: String) on FIELD_DEFINITION

interface API implements Entity & Node & Ownable {
annotations: [KeyValuePair!]
Expand Down Expand Up @@ -2436,7 +2436,7 @@ export type DiscriminationAliasDirectiveArgs = {
export type DiscriminationAliasDirectiveResolver<Result, Parent, ContextType = any, Args = DiscriminationAliasDirectiveArgs> = DirectiveResolverFn<Result, Parent, ContextType, Args>;

export type FieldDirectiveArgs = {
at: Scalars['_DirectiveArgument_']['input'];
at?: Maybe<Scalars['_DirectiveArgument_']['input']>;
default?: Maybe<Scalars['_DirectiveArgument_']['input']>;
};

Expand All @@ -2459,6 +2459,7 @@ export type RelationDirectiveResolver<Result, Parent, ContextType = any, Args =
export type ResolveDirectiveArgs = {
at?: Maybe<Scalars['_DirectiveArgument_']['input']>;
from?: Maybe<Scalars['String']['input']>;
nodeType?: Maybe<Scalars['String']['input']>;
};

export type ResolveDirectiveResolver<Result, Parent, ContextType = any, Args = ResolveDirectiveArgs> = DirectiveResolverFn<Result, Parent, ContextType, Args>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { JsonObject } from '@backstage/types';
import {
createGraphQLApp,
GraphQLContext,
CoreSync,
} from '@frontside/hydraphql';

import * as graphql from 'graphql';
Expand All @@ -12,15 +11,15 @@ import { Module } from 'graphql-modules';
import { envelop, useEngine } from '@envelop/core';
import { useDataLoader } from '@envelop/dataloader';
import { useGraphQLModules } from '@envelop/graphql-modules';
import { RelationSync } from '../relation';
import { Relation } from '../relation';

export async function createGraphQLAPI(
TestModule: Module,
loader: (context: GraphQLContext) => DataLoader<any, any>,
generateOpaqueTypes?: boolean,
) {
const application = await createGraphQLApp({
modules: [CoreSync(), RelationSync(), TestModule],
modules: [Relation(), TestModule],
generateOpaqueTypes,
});

Expand Down
25 changes: 9 additions & 16 deletions plugins/graphql-backend-module-catalog/src/catalog/catalog.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { createModule, TypeDefs } from 'graphql-modules';
import { createModule } from 'graphql-modules';
import GraphQLJSON, { GraphQLJSONObject } from 'graphql-type-json';
import { relationDirectiveMapper } from '../relationDirectiveMapper';
import {
createDirectiveMapperProvider,
GraphQLModule,
encodeId,
} from '@frontside/hydraphql';
import { stringifyEntityRef } from '@backstage/catalog-model';
import { loadFiles, loadFilesSync } from '@graphql-tools/load-files';
import { loadFilesSync } from '@graphql-tools/load-files';
import { resolvePackagePath } from '@backstage/backend-common';
import { CATALOG_SOURCE } from '../constants';

Expand All @@ -16,12 +16,11 @@ const catalogSchemaPath = resolvePackagePath(
);

/** @public */
export const CatalogSync = (
typeDefs: TypeDefs = loadFilesSync(catalogSchemaPath),
) =>
createModule({
export const Catalog = (): GraphQLModule => ({
mappers: { relation: relationDirectiveMapper },
module: createModule({
id: 'catalog',
typeDefs,
typeDefs: loadFilesSync(catalogSchemaPath),
resolvers: {
JSON: GraphQLJSON,
JSONObject: GraphQLJSONObject,
Expand Down Expand Up @@ -55,11 +54,5 @@ export const CatalogSync = (
}),
},
},
providers: [
createDirectiveMapperProvider('relation', relationDirectiveMapper),
],
});

/** @public */
export const Catalog = async () =>
CatalogSync(await loadFiles(catalogSchemaPath));
})
});
25 changes: 9 additions & 16 deletions plugins/graphql-backend-module-catalog/src/relation/relation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TypeDefs, createModule } from 'graphql-modules';
import { createModule } from 'graphql-modules';
import { relationDirectiveMapper } from '../relationDirectiveMapper';
import { createDirectiveMapperProvider } from '@frontside/hydraphql';
import { loadFiles, loadFilesSync } from '@graphql-tools/load-files';
import { GraphQLModule } from '@frontside/hydraphql';
import { loadFilesSync } from '@graphql-tools/load-files';
import { resolvePackagePath } from '@backstage/backend-common';

const relationSchemaPath = resolvePackagePath(
Expand All @@ -10,17 +10,10 @@ const relationSchemaPath = resolvePackagePath(
);

/** @public */
export const RelationSync = (
typeDefs: TypeDefs = loadFilesSync(relationSchemaPath),
) =>
createModule({
export const Relation = (): GraphQLModule => ({
mappers: { relation: relationDirectiveMapper },
module: createModule({
id: 'relation',
typeDefs,
providers: [
createDirectiveMapperProvider('relation', relationDirectiveMapper),
],
});

/** @public */
export const Relation = async () =>
RelationSync(await loadFiles(relationSchemaPath));
typeDefs: loadFilesSync(relationSchemaPath),
})
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
CoreSync,
transformSchema,
encodeId,
decodeId,
Expand All @@ -8,13 +7,12 @@ import DataLoader from 'dataloader';
import { DocumentNode, GraphQLNamedType, printType } from 'graphql';
import { createModule, gql } from 'graphql-modules';
import { createGraphQLAPI } from './__testUtils__';
import { RelationSync } from './relation/relation';
import { Relation } from './relation/relation';

describe('mapRelationDirective', () => {
const transform = (source: DocumentNode) =>
transformSchema([
CoreSync(),
RelationSync(),
Relation(),
createModule({
id: 'mapRelationDirective',
typeDefs: source,
Expand Down
Loading

0 comments on commit dd62c62

Please sign in to comment.