Skip to content

Commit

Permalink
Merge branch 'main' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor-scheer committed Nov 10, 2023
2 parents 51c26a0 + 88d67fd commit a40d9d0
Show file tree
Hide file tree
Showing 25 changed files with 377 additions and 319 deletions.
10 changes: 10 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ version: 2.1

orbs:
node: circleci/[email protected]
secops: apollo/[email protected]

jobs:
# Unfortunately cimg/node doesn't tag its images with major only, you have to specify a minor version.
Expand Down Expand Up @@ -58,3 +59,12 @@ workflows:
- node/run:
name: Check Prettier (tests)
npm-run: prettier:check
security-scans:
jobs:
- secops/gitleaks:
context:
- platform-docker-ro
- github-orb
- secops-oidc
git-base-revision: <<#pipeline.git.base_revision>><<pipeline.git.base_revision>><</pipeline.git.base_revision >>
git-revision: << pipeline.git.revision >>
1 change: 1 addition & 0 deletions .cspell/cspell-dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ Queryf
reacheable
reasonse
recusive
redeclaration
refered
Referencer
referencer
Expand Down
10 changes: 10 additions & 0 deletions composition-js/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# CHANGELOG for `@apollo/composition`

## 2.5.6
### Patch Changes


- Fixing issue where redeclaration of custom scalars in a fed1 schema may cause upgrade errors ([#2809](https://github.com/apollographql/federation/pull/2809))

- Updated dependencies [[`c719214a`](https://github.com/apollographql/federation/commit/c719214a945564e4afc4bf1610e3dcdfb3838fe1)]:
- @apollo/federation-internals@2.5.6
- @apollo/query-graphs@2.5.6

## 2.5.5
### Patch Changes

Expand Down
6 changes: 3 additions & 3 deletions composition-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@apollo/composition",
"version": "2.5.5",
"version": "2.5.6",
"description": "Apollo Federation composition utilities",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -27,8 +27,8 @@
"access": "public"
},
"dependencies": {
"@apollo/federation-internals": "2.5.5",
"@apollo/query-graphs": "2.5.5"
"@apollo/federation-internals": "2.5.6",
"@apollo/query-graphs": "2.5.6"
},
"peerDependencies": {
"graphql": "^16.5.0"
Expand Down
18 changes: 18 additions & 0 deletions composition-js/src/__tests__/composeFed1Subgraphs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -727,4 +727,22 @@ describe('override', () => {
'[subgraphB] Invalid definition for directive \"@override\": missing required argument "from"',
]]);
});

it('repro redefined built-in scalar breaks @key directive', () => {
const subgraphA = {
typeDefs: gql`
scalar Boolean
type Query {
q: String
}
type A @key(fields: "k") {
k: ID!
}
`,
name: 'subgraphA',
};

const result = composeServices([subgraphA,]);
assertCompositionSuccess(result);
});
});
59 changes: 29 additions & 30 deletions docs/source/building-supergraphs/supported-subgraphs.md

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions docs/source/entities-advanced.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,24 @@ type Product @key(fields: "id", resolvable: false) {
type Product @key(fields: "sku", resolvable: false) {
sku: String!
}
```

When resolving a reference for an entity with multiple keys, you can determine how to resolve it based on which key is present. For example, if you're using [`@apollo/subgraph`](/apollo-server/using-federation/api/apollo-subgraph/), it could look like this:

```js title="resolvers.js"
// Products subgraph
const resolvers = {
Product: {
__resolveReference(productRepresentation) {
if(productRepresentation.sku){
return fetchProductBySku(productRepresentation.sku);
} else {
return fetchProductByID(productRepresentation.id);
}
}
},
// ...other resolvers...
}
```

### Differing `@key`s across subgraphs
Expand Down
30 changes: 2 additions & 28 deletions docs/source/federated-types/sharing-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -137,35 +137,9 @@ To make `Position.z` shareable, you can do one of the following:

## Differing shared fields

Shared fields can differ between subgraphs in specific ways:
* The return type of a shared field can vary in nullability (`String` / `String!`).
* A shared field's return type _can't_ vary in its core type (`Int` vs. `String`) or in whether it returns a list (`Int` vs. `[Int]`).
* A field can be omitted from a subgraph, _if_ that field is always [resolvable](../federated-types/composition/#rules-of-composition).
Shared fields can only differ in their [return types](#return-types) and [arguments](#arguments) in specific ways.
If fields you want to share between subgraphs differ more than is permitted, use [entities](../entities) instead of shareable value types.

For example, take a look at the shared `Food` type below:

<CodeColumns>

```graphql {3} title="Subgraph A"
type Food @shareable {
name: String!
price: Int!
}
```

```graphql {3-4} title="Subgraph B"
type Food @shareable {
name: String!
price: Int # Nullable
inStock: Boolean! # Not in A
}
```

<></>

</CodeColumns>

The above `Food` types differ in the nullability of their fields _and_ the fields included in each type.

### Return types

Expand Down
2 changes: 2 additions & 0 deletions federation-integration-testsuite-js/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# CHANGELOG for `federation-integration-testsuite-js`

## 2.5.6

## 2.5.5

## 2.5.4
Expand Down
2 changes: 1 addition & 1 deletion federation-integration-testsuite-js/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "apollo-federation-integration-testsuite",
"private": true,
"version": "2.5.5",
"version": "2.5.6",
"description": "Apollo Federation Integrations / Test Fixtures",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
8 changes: 8 additions & 0 deletions gateway-js/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# CHANGELOG for `@apollo/gateway`

## 2.5.6
### Patch Changes

- Updated dependencies [[`c719214a`](https://github.com/apollographql/federation/commit/c719214a945564e4afc4bf1610e3dcdfb3838fe1)]:
- @apollo/composition@2.5.6
- @apollo/federation-internals@2.5.6
- @apollo/query-planner@2.5.6

## 2.5.5
### Patch Changes

Expand Down
8 changes: 4 additions & 4 deletions gateway-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@apollo/gateway",
"version": "2.5.5",
"version": "2.5.6",
"description": "Apollo Gateway",
"author": "Apollo <[email protected]>",
"main": "dist/index.js",
Expand All @@ -25,9 +25,9 @@
"access": "public"
},
"dependencies": {
"@apollo/composition": "2.5.5",
"@apollo/federation-internals": "2.5.5",
"@apollo/query-planner": "2.5.5",
"@apollo/composition": "2.5.6",
"@apollo/federation-internals": "2.5.6",
"@apollo/query-planner": "2.5.6",
"@apollo/server-gateway-interface": "^1.1.0",
"@apollo/usage-reporting-protobuf": "^4.1.0",
"@apollo/utils.createhash": "^2.0.0",
Expand Down
6 changes: 6 additions & 0 deletions internals-js/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG for `@apollo/federation-internals`

## 2.5.6
### Patch Changes


- Fixing issue where redeclaration of custom scalars in a fed1 schema may cause upgrade errors ([#2809](https://github.com/apollographql/federation/pull/2809))

## 2.5.5

## 2.5.4
Expand Down
2 changes: 1 addition & 1 deletion internals-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@apollo/federation-internals",
"version": "2.5.5",
"version": "2.5.6",
"description": "Apollo Federation internal utilities",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
15 changes: 10 additions & 5 deletions internals-js/src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
InterfaceType,
isInputObjectType,
isNonNullType,
isScalarType,
NamedSchemaElement,
ObjectType,
Schema,
Expand All @@ -17,7 +18,7 @@ import {
VariableDefinitions
} from "./definitions";
import { assertName, ASTNode, GraphQLError, GraphQLErrorOptions } from "graphql";
import { isValidValue, valueToString } from "./values";
import { isValidValue, valueToString, isValidValueApplication } from "./values";
import { introspectionTypeNames, isIntrospectionName } from "./introspection";
import { isSubtype, sameType } from "./types";
import { ERRORS } from "./error";
Expand Down Expand Up @@ -290,10 +291,14 @@ class Validator {
);
}
if (arg.defaultValue !== undefined && !isValidValue(arg.defaultValue, arg, new VariableDefinitions())) {
this.addError(
`Invalid default value (got: ${valueToString(arg.defaultValue)}) provided for argument ${arg.coordinate} of type ${arg.type}.`,
{ nodes: sourceASTs(arg) },
);
// don't error if custom scalar is shadowing a builtin scalar
const builtInScalar = this.schema.builtInScalarTypes().find((t) => arg.type && isScalarType(arg.type) && t.name === arg.type.name);
if (!builtInScalar || !isValidValueApplication(arg.defaultValue, builtInScalar, arg.defaultValue, new VariableDefinitions())) {
this.addError(
`Invalid default value (got: ${valueToString(arg.defaultValue)}) provided for argument ${arg.coordinate} of type ${arg.type}.`,
{ nodes: sourceASTs(arg) },
);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion internals-js/src/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ export function isValidValue(value: any, argument: ArgumentDefinition<any> | Inp
return isValidValueApplication(value, argument.type!, argument.defaultValue, variableDefinitions);
}

function isValidValueApplication(value: any, locationType: InputType, locationDefault: any, variableDefinitions: VariableDefinitions): boolean {
export function isValidValueApplication(value: any, locationType: InputType, locationDefault: any, variableDefinitions: VariableDefinitions): boolean {
// Note that this needs to be first, or the recursive call within 'isNonNullType' would break for variables
if (isVariable(value)) {
const definition = variableDefinitions.definition(value);
Expand Down
Loading

0 comments on commit a40d9d0

Please sign in to comment.