Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
add defautl for operationName and removed Http comment from websocket…
Browse files Browse the repository at this point in the history
… link
  • Loading branch information
evans committed Aug 4, 2017
1 parent f449fa8 commit 531daf6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
9 changes: 4 additions & 5 deletions packages/apollo-link-core/src/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export function execute(
}

function getName(node: OperationDefinitionNode) {
return node.name && node.name.kind === 'Name' && node.name.value;
return node && node.name && node.name.kind === 'Name' && node.name.value;
}

function transformOperation(operation: GraphQLRequest): Operation {
Expand All @@ -165,11 +165,10 @@ function transformOperation(operation: GraphQLRequest): Operation {
operationTypes.indexOf(x.operation) >= 0,
);

if (definitions.length) {
const definition = definitions[0];
transformedOperation.operationName = getName(definition);
}
transformedOperation.operationName = getName(definitions[0]) || '';
}
} else if (!transformedOperation.operationName) {
transformedOperation.operationName = '';
}

return transformedOperation;
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-link-core/tests/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ describe('Link static library', () => {
assert.notProperty(operation, 'variables');
assert.notProperty(operation, 'context');
assert.property(op, 'query');
// assert.property(op, 'operationName'); isn't automatically set if not present
assert.property(op, 'operationName');
assert.property(op, 'variables');
assert.property(op, 'context');
return Observable.of();
Expand Down
3 changes: 0 additions & 3 deletions packages/apollo-link-ws/src/webSocketLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ export type WebSocketParams = {
webSocketImpl?: any;
};

/** Transforms Operation for into HTTP results.
* context can include the headers property, which will be passed to the fetch function
*/
export default class WebSocketLink extends ApolloLink {
private subscriptionClient: SubscriptionClient;

Expand Down

0 comments on commit 531daf6

Please sign in to comment.