Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graphql-voyager: bump dep to 2.0 + add dev setup #19364

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/odd-students-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage/theme': patch
---

Workaround for style type inconsistencies within Material-UI v4 that could cause type errors when using font weights from the theme as styles.
5 changes: 5 additions & 0 deletions .changeset/tidy-foxes-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage/plugin-graphql-voyager': minor
---

Bumped `graphql-voyager` dependency to 2.0. The `workerURI` and `loadWorker` options have been removed, as they are not longer needed.
1 change: 1 addition & 0 deletions packages/theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
},
"peerDependencies": {
"@material-ui/core": "^4.12.2",
"@material-ui/styles": "^4.11.0",
"@types/react": "^16.13.1 || ^17.0.0",
"react": "^16.13.1 || ^17.0.0",
"react-dom": "^16.13.1 || ^17.0.0"
Expand Down
19 changes: 19 additions & 0 deletions packages/theme/src/v4/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type {
PaletteOptions as MuiPaletteOptions,
Palette as MuiPalette,
} from '@material-ui/core/styles/createPalette';
import { CSSProperties } from '@material-ui/styles/withStyles';
import {
BackstagePaletteAdditions,
BackstageThemeAdditions,
Expand Down Expand Up @@ -104,3 +105,21 @@ declare module '@material-ui/core/styles/createTheme' {

interface ThemeOptions extends Partial<BackstageThemeAdditions> {}
}

// This fixes as type incompatibility that is caused by a variance in the declaration of
// the font weight types in the MUI v4 theme typography and styles such as through `makeStyles()`.
// The font weight in styles are defined to be `CSSProperties["fontWeight"]` from `csstype`, while the
// front weight in the typography are defined to be `React.CSSProperties["fontWeight"]` from `@types/react`.
//
// This is usually not an issue, but with a bad combination of `csstype` version and the wrong Yarn workspace
// hoisting, you can end up in a case where font weights from the theme are not assignable as styles.
//
// This makes sure that the font weights in the theme are compatible with the styles.
declare module '@material-ui/core/styles/createTypography' {
interface Typography {
fontWeightLight: CSSProperties['fontWeight'];
fontWeightRegular: CSSProperties['fontWeight'];
fontWeightMedium: CSSProperties['fontWeight'];
fontWeightBold: CSSProperties['fontWeight'];
}
}
Comment on lines +118 to +125
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting. I'm not sure it's v4-specific, but rather the combination of v4 & v5 I would assume. Would be happy with this work around, if it fixes csstypes issue for now!

3 changes: 0 additions & 3 deletions plugins/graphql-voyager/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { ApiRef } from '@backstage/core-plugin-api';
import { BackstagePlugin } from '@backstage/core-plugin-api';
import { RouteRef } from '@backstage/core-plugin-api';
import { VoyagerDisplayOptions } from 'graphql-voyager/typings/components/Voyager';
import { WorkerCallback } from 'graphql-voyager/typings/utils/types';

// @public (undocumented)
export type GraphQLVoyagerApi = {
Expand All @@ -29,8 +28,6 @@ export type GraphQLVoyagerEndpoint = {
displayOptions?: VoyagerDisplayOptions;
hideDocs?: boolean;
hideSettings?: boolean;
workerURI?: string;
loadWorker?: WorkerCallback;
};
};

Expand Down
60 changes: 60 additions & 0 deletions plugins/graphql-voyager/dev/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2020 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import React from 'react';
import { createDevApp } from '@backstage/dev-utils';
import {
graphqlVoyagerPlugin,
graphQlVoyagerApiRef,
GraphQLVoyagerEndpoints,
GraphqlVoyagerPage,
} from '../src';

createDevApp()
.registerPlugin(graphqlVoyagerPlugin)
.registerApi({
api: graphQlVoyagerApiRef,
deps: {},
factory() {
return GraphQLVoyagerEndpoints.from([
{
id: 'graphql-voyager-endpoint-id',
title: 'Countries',
introspectionErrorMessage:
'Unable to perform introspection, make sure you are on the correct environment.',
introspection: async query => {
const res = await fetch('https://countries.trevorblades.com', {
method: 'POST',
body: JSON.stringify({ query }),
headers: {
'Content-Type': 'application/json',
},
});

return res.json();
},
voyagerProps: {
hideDocs: true,
},
},
]);
},
})
.addPage({
title: 'GQL Voyager',
element: <GraphqlVoyagerPage />,
})
.render();
2 changes: 1 addition & 1 deletion plugins/graphql-voyager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@material-ui/core": "^4.12.2",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.61",
"graphql-voyager": "^1.0.0-rc.31",
"graphql-voyager": "^2.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI:
graphql-voyager v2.0.0 upgraded from (previously at RC31) material-ui v4 to v5

    "@mui/icons-material": "5.11.0",
    "@mui/lab": "5.0.0-alpha.114",
    "@mui/material": "5.11.2",

PS: This PR could resolve #19327 and #19326.

The RC31 was dependent on "@material-ui/core": ^3.9.3 -> recompose: 0.28.0 - 0.30.0 -> fbjs: ^0.8.1 -> isomorphic-fetch: ^2.1.1 -> node-fetch: ^1.0.1

"react-use": "^17.2.4"
},
"peerDependencies": {
Expand Down
3 changes: 0 additions & 3 deletions plugins/graphql-voyager/src/lib/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
import { createApiRef } from '@backstage/core-plugin-api';
import { VoyagerDisplayOptions } from 'graphql-voyager/typings/components/Voyager';
import { WorkerCallback } from 'graphql-voyager/typings/utils/types';

/** @public */
export type GraphQLVoyagerEndpoint = {
Expand All @@ -27,8 +26,6 @@ export type GraphQLVoyagerEndpoint = {
displayOptions?: VoyagerDisplayOptions;
hideDocs?: boolean;
hideSettings?: boolean;
workerURI?: string;
loadWorker?: WorkerCallback;
};
};

Expand Down